Problem with Automation not triggering

The reason I’ve tried this is because I’ve got a kettle that sometimes doesn’t automatically stops so I want to set a timer to turn of the switch when the kettle have been on and running for 6 mins (top boiling time for full kettle)

So I thought I’d use the “Add Automation” page. Seamed straight forward but nu luck. The automation doesn’t trigger.

Tried to restart and reload everything.

Any help is greatly appreciated!

This is the code that was put in the /config/automations.yaml
(removed id’s and replaced with xxx)

- id: 'xxx'
  alias: Turn of kettle after 3 min and its on
  description: ''
  trigger:
  - platform: state
    to: 'on'
    entity_id: switch.kitchen_kettle_switch
    from: 'off'
  condition:
  - type: is_power
    condition: device
    device_id: xxx
    entity_id: sensor.kitchen_kettle_power
    domain: sensor
    above: 2000
  - condition: device
    type: is_on
    device_id: xxx
    entity_id: switch.kitchen_kettle_switch
    domain: switch
    for:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  action:
  - type: turn_off
    device_id: xxx
    entity_id: switch.kitchen_kettle_switch
    domain: switch
  mode: single

Should as well that the trigger is me pressing the button on the smart plug. It registers in the dashboard when I toggle the button on the plug. Also tried triggering from HA but no difference.

Basically, this:

- alias: Kettle automatic off
  id: kettle_auto_off
  trigger:
  - platform: state
    entity_id: switch.kitchen_kettle_switch
    from: 'off'
    to: 'on'
    for: '00:06:00'
  action:
  - service: switch.turn_off
    target:
      entity_id: switch.kitchen_kettle_switch

the reason why your current automation isn’t working correctly is the trigger:

trigger:
  - platform: state
    to: 'on'
    entity_id: switch.kitchen_kettle_switch
    from: 'off'

happens instantly as soon as you turn on the switch.

But the condition:

condition:
  ...
  - condition: device
    type: is_on
    device_id: xxx
    entity_id: switch.kitchen_kettle_switch
    domain: switch
    for:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0

says that it can only perform the actions if the switch has already been on for 10 seconds after the trigger is satisfied.

Those two things are mutually exclusive.

the conditions must be satisfied already at the moment the trigger occurs. the automation won’t wait for the conditions after the trigger is set.

So you need to use the trigger as in Taras example above.

But you can still use the power checking condition as well if you think you really need it.

Thank you, Worked like a charm.
.

I didn’t give you the solution. I only gave you the explanation of why your original one didn’t work.

You should give @123 the solution mark.

Thank you for pointing it out, as you see new to this community.

1 Like