Automations in release 0.113

according to Thomas, this would have to be possible:

You can also merge an anchor if you want to add more entries to the dict:

base: &base
  a: 1
  b: 2

extended version:
  <<: *base
  c: 3

That’s a dictionary, not a list. Yes, it’s supported for those, but not for lists, as far as I can tell.

After upgrading to 0.113 I have changed the following automations

- alias: Lamp toilet aan bij beweging geconstateerd door bewegingssensor
  trigger:
    - platform: state
      entity_id: binary_sensor.bewegingsensor_toilet
      from: 'off'
      to: 'on'
  action:
    - service: switch.turn_on
      entity_id: switch.shelly_toilet

- alias: Lamp toilet uit bij geen beweging meer
  trigger:
    - platform: state
      entity_id: binary_sensor.bewegingsensor_toilet
      from: 'on'
      to: 'off'
      for:
        minutes: 5
  action:
    - service: switch.turn_off
      entity_id: switch.shelly_toilet

to

- alias: Lamp toilet aan en uit bij beweging geconstateerd door bewegingssensor
  id: 3c4229f5-bcef-4b2c-8538-9b855d9f7695
  trigger:
    - platform: state
      entity_id: binary_sensor.bewegingsensor_toilet
  action:
    - choose:
      - conditions:
        - condition: state
          entity_id: binary_sensor.bewegingsensor_toilet
          state: 'on'
        sequence:
          - service: switch.turn_on
            entity_id: switch.shelly_toilet
      - conditions:
        - condition: state
          entity_id: binary_sensor.bewegingsensor_toilet
          state: 'off'
          for:
            minutes: 5
        sequence:
          - service: switch.turn_off
            entity_id: switch.shelly_toilet

But then the light doesn’t go off anymore.
Am I missing something here or does the for part not work for this?
I am on 113.1 btw as I saw some issues with TTS with 113.2.

The for part in a state condition does not mean exactly the same thing as it does in a state trigger. In the trigger it actually waits for the entity to be in the specified state for that amount of time. But in a condition it only cares if the entity has been in that state for that amount of time. So you’re triggering when the sensor goes off, but then checking if it has been off for 5 minutes, which, of course, it has not been.

This is another case where a service_template would be much easier, but the real issue is you’re no longer waiting for the sensor to be off for 5 minutes before doing something.

If you really want to use chose over service_template, then here’s what I would suggest:

- alias: Lamp toilet aan en uit bij beweging geconstateerd door bewegingssensor
  id: 3c4229f5-bcef-4b2c-8538-9b855d9f7695
  trigger:
    - platform: state
      entity_id: binary_sensor.bewegingsensor_toilet
      to:
        - 'on'
        - 'off'
  mode: restart
  action:
    - choose:
      - conditions:
        - condition: state
          entity_id: binary_sensor.bewegingsensor_toilet
          state: 'on'
        sequence:
          - service: switch.turn_on
            entity_id: switch.shelly_toilet
      default:
        - delay: "00:05"
        - service: switch.turn_off
          entity_id: switch.shelly_toilet
1 Like

Thanks for your explanation and example! That makes sense indeed.
The service_template version would look like this then?

- alias: Lamp toilet aan en uit bij beweging geconstateerd door bewegingssensor
  id: 3c4229f5-bcef-4b2c-8538-9b855d9f7695
  trigger:
    - platform: state
      entity_id: binary_sensor.bewegingsensor_toilet
      from: 'off'
      to: 'on'
    - platform: state
      entity_id: binary_sensor.bewegingsensor_toilet
      from: 'on'
      to: 'off'
      for:
        minutes: 5
  action:
    - service_template: "switch.turn_{{ trigger.to_state.state }}"
      entity_id: switch.shelly_toilet
1 Like