Template sensor stop working with paralell auromations

I have shelly 2PM with two “deatached” input switch. I use this two input as garage door limit sensor with reed relays.

Sensor code:

 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: >
        {% if (states('binary_sensor.garage_door_input_s1_open') == 'unavailable' or states('binary_sensor.garage_door_input_s2_closed') == 'unavailable')  %}
            unknow
        {% elif (states('binary_sensor.garage_door_input_s1_open') == 'on' and states('binary_sensor.garage_door_input_s2_closed') == 'on') %}
            sabotage
        {% elif (trigger.to_state.state == 'on' and trigger.entity_id == 'binary_sensor.garage_door_input_s1_open') %}
            open
        {% elif (trigger.to_state.state == 'on' and trigger.entity_id == 'binary_sensor.garage_door_input_s2_closed') %}
            closed
        {% elif (trigger.from_state.state == 'on' and trigger.to_state.state == 'off' and trigger.entity_id == 'binary_sensor.garage_door_input_s1_open') %}
            closing
        {% elif (trigger.from_state.state == 'on' and trigger.to_state.state == 'off' and trigger.entity_id == 'binary_sensor.garage_door_input_s2_closed') %}
            opening
        {% endif %}

When closing or opening state present my automation start a timer for 30 sec:

alias: Garage Door aut.
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.garage_door_input_s1_open
    from: "on"
    to: "off"
conditions: []
actions:
  - action: timer.start
    metadata: {}
    data: {}
    target:
      entity_id: timer.garage_time

In this case when binary_sensor.garage_door_input_s1_open state on>off

timer start but sensor state is empty (but there should be “closing”)
If i disable automations states work fine. Where is a problem???

Are there errors in your logs?

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.

1 Like

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 :slight_smile: