why are you using 4 sensors to define the state instead of a single sensor with 4 states? You’re over complicating it. Secondly, if you switch to a single sensor, you won’t need appdaemon to handle anything. A single template sensor can do the job. Lastly, you can use the previous state of the single sensor to determine what the new state will be. I.E. if the last state was closed and both sensors are off, then you’re opening. If the last state was open and both states are off, then you’re closing.
template:
- sensor:
- name: Vorota state
state: >
{% set open_on = is_state('binary_sensor.0x00124b0022fef19f_contact','on') %}
{% set close_on = is_state('binary_sensor.vorota_zakryty_contact','on') %}
{% if open_on and not close_on %}
open
{% elif not open_on and close_on %}
closed
{% elif open_on and close_on %}
sensor error
{% else %}
{% if is_state('sensor.vorota_state', 'open') %}
closing
{% else %}
opening
{% endif %}
{% endif %}