There are gates with limit switches (binary_sensors ‘lsopened’ and ‘lsclosed’).
Based on the combination of limit switches, the status of the gate is formed (open, closed, half-open) (sensor ‘experimental_gate_status’)
I want change sensor ‘experimental_gate_status’ not via ‘update_interval’ and after change binary_sensors limit swithes.
ESPHome code:
binary_sensor:
- platform: gpio
id: lsopened
name: "Limit switch 'Opened'"
pin: GPIO0 # D3 - limit switch (opened)
filters:
- invert
- lambda: |-
id(experimental_gate_status).update();
return int(x);
- platform: gpio
id: lsclosed
name: "Limit switch 'Closed'"
pin: GPIO4 # D2 - limit switch (closed)
filters:
- invert
- lambda: |-
id(experimental_gate_status).update();
return int(x);
sensor:
- platform: template
name: "Experimental Gate status"
id: experimental_gate_status
lambda: |-
return ((id(lsclosed).state)*10 + id(lsopened).state);
update_interval: never
force_update: true
But if I use this code
id(experimental_gate_status).update();
return int(x);
then the gate status sensor is updated first (id(experimental_gate_status).update();
)
And then by return int(x);
the state of the limit switch is updated.
As a result, I get the status of the gate status based on the previous state of the limit switches.