Wow. After I got the rule engine working again, I could reduce the code to a minimum.
My project was modifying a 3-Way pool valve from a pre-fabricated controller

- 2021-07-06_19-49-05.jpg (21.59 KiB) Viewed 14750 times
to being managed by ESPEasy with easy toggle switch and valve status indication

.

- 2021-07-06_19-47-23.jpg (148.97 KiB) Viewed 14750 times
Status can be controlled/viewed in Home Assistant

- 2021-07-06_19-49-35.jpg (8.35 KiB) Viewed 14750 times
Love it
All that's missing is the automatic temperature control with different mode-settings, which I need to get my head around.
Code:
Code: Select all
on MQTT1#Direction do
if %eventvalue1%!=[Dummy1#Direction]
asyncevent,SetState=%eventvalue1%
endif
endon
on Button#State=0 do
let,1,1-[Dummy1#Direction]
asyncevent,SetState=[VAR#1]
endon
on SetState do
timerset,2,0
timerset,3,0
taskvalueset,7,1,%eventvalue1%
if %eventvalue1%=1
publish "Pool_3wayValve/Valve_status","Moving to solar"
mcpgpio,10,1 // RED ON
mcpgpio,11,0 // Green OFF
mcpgpio,13,1 // Solar heater
else
publish "Pool_3wayValve/Valve_status","Moving to direct"
mcpgpio,10,0 // Red OFF
mcpgpio,11,1 // GREEN ON
mcpgpio,13,0 // Direct
endif
mcpgpio,12,0 // Power ON
timerset,2,17
looptimerset_ms,3,400
endon
on Rules#Timer=2 do
mcpgpio,12,1 // Power OFF
mcpgpio,13,1 // No power to direction
timerset,3,0
if [Dummy1#Direction]=0
publish "Pool_3wayValve/Valve_status","Direct"
else
publish "Pool_3wayValve/Valve_status","Solar"
endif
endon
on Rules#Timer=3 do
if [Dummy1#Direction]=1 // Reversed
MCPLongPulse_ms,10,0,200
else
MCPLongPulse_ms,11,0,200
endif
endon