Sidebar: I’d redo the template syntax because it doesn’t account for unknown in the state and you aren’t utilizing else. There may be some odd circumstances where those values are hit resulting in an empty state.
trigger:
- platform: state
entity_id:
- binary_sensor.garage_door_input_s1_open
- binary_sensor.garage_door_input_s2_closed
sensor:
- name: Garage Status
unique_id: garage_status
state: >
{% set open_id = 'binary_sensor.garage_door_input_s1_open' %}
{% set closed_id = 'binary_sensor.garage_door_input_s2_closed' %}
{% if open_id | has_value and closed_id | has_value %}
{% if is_state(open_id, 'on') and is_state(closed_id, 'on') %}
sabotage
{% elif trigger.entity_id == open_id %}
clos{{ 'ed' if trigger.to_state.state == 'on' else 'ing' }}
{% else %}
open{{ '' if trigger.to_state.state == 'on' else 'ing' }}
{% endif %}
{% else %}
unknown
{% endif %}
The original code works good if automation disabled. All conditions evaluated.
But if automation is enabled timer start when state should be “closing” sensor state is empty “”
If disable automations again sensor works pretty good
The 2 systems are separate and they do not impact each other. You’re likely running into an issue when you reload, meaning the issue is only in your template entity. Please try the simplified syntax that accounts for all possible erroneous states.
EDIT: Also keep in mind, both templates do not handle reloads properly. They only handle restarts.
So, your code is working, I’m begginer I dont understand where is significant difference between two code. The fiinal goal:
When door is moving (opening or closing) timer (30 sec) is start. If door reach sooner end position the state changed to open or closed and timer stoped and reset. If timer is ends and no end position the sensor state is “error” or something similar and if possibe push a button entity “alarm” or start automation or script??? Thank you your patience and help