Automation not triggering, whats wrong?

Hello,
today i wanted to create my first homeassistant automation.
Somehow it doesnt trigger it.

My automation:

description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.pv_heizung_power
    above: '200'
    for: 5m
condition:
  - condition: time
    after: '13:00'
  - condition: device
    type: is_off
    device_id: 3889921153e8baec2a95442c97ec1e93
    entity_id: switch.shelly1_e8db84a93a46
    domain: switch
    for:
      hours: 1
      minutes: 0
      seconds: 0
      milliseconds: 0
action:
  - type: turn_on
    device_id: 3889921153e8baec2a95442c97ec1e93
    entity_id: switch.shelly1_e8db84a93a46
    domain: switch
mode: single

Secound screenshow (can only post one in here): http://puu.sh/HUwzN.png

It was triggered manualy in screenshot

What’s wrong with my automation?

Compare your trigger to the documentation. Specifically look at the for portion. Your current for is not correct in your trigger. You’re correctly using for in your condition but not in your trigger. So you can even use your own automation as a guide to help you.

Your automation will trigger when:

  • the power goes from below to above 200W and
  • it’s after 13:00 and
  • the switch has been off for an hour

Your graph shows that the power does not cross the 200W threshold after 13:00, so it won’t trigger (as well as @petro’s observation).

A fix would be to add a time trigger at 13:00, and a condition to check the power is above 200W.

1 Like

Thank you for your fast respones.

Is the following code correct?

alias: Heizung einschalten 200 Watt nach 13 Uhr
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.pv_heizung_power
    above: '200'
    for: '0:05:00'
  - platform: time
    at: '13:00'
condition:
  - condition: time
    after: '13:00'
  - condition: device
    type: is_off
    device_id: 3889921153e8baec2a95442c97ec1e93
    entity_id: switch.shelly1_e8db84a93a46
    domain: switch
    for:
      hours: 1
      minutes: 0
      seconds: 0
      milliseconds: 0
  - condition: numeric_state
    entity_id: sensor.pv_heizung_power
    above: '200'
action:
  - type: turn_on
    device_id: 3889921153e8baec2a95442c97ec1e93
    entity_id: switch.shelly1_e8db84a93a46
    domain: switch
mode: single

Looks OK to me. If this were my automation, I’d swap the device bits for entity-based alternatives, and write the fors consistently, but this is all aesthetics rather than functionality. I’ve also added an id so it works with the automation debugging tool:

alias: Heizung einschalten 200 Watt nach 13 Uhr
id: 96fe0432-e4e5-4eba-b2c2-a307c724bb09

trigger:
  - platform: numeric_state
    entity_id: sensor.pv_heizung_power
    above: 200
    for:
      minutes: 5
  - platform: time
    at: "13:00"

condition:
  - condition: time
    after: "13:00"
  - condition: state
    entity_id: switch.shelly1_e8db84a93a46
    state: "off"
    for:
      hours: 1
  - condition: numeric_state
    entity_id: sensor.pv_heizung_power
    above: 200

action:
  - service: homeassistant.turn_on
    entity_id: switch.shelly1_e8db84a93a46

Worth noting that this still won’t trigger at 13:00 if the switch has been off for less than an hour.

Should i do a trigger that triggers every 5 minutes and remove the other 2 triggers?

No. Time pattern triggers are a last resort. You could add a third trigger:

  - platform: state
    entity_id: switch.shelly1_e8db84a93a46
    to: "off"
    for:
      hours: 1

Then you have matching triggers and conditions, such that any of the triggers can fire, but the action will only happen if all the conditions are true.

And another problem i have is, that my turn off automation doesnt work too.

alias: Heizung ausschalten PV 15m unter 100W und Heizung 1h ein
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.pv_heizung_power
    below: '150'
    for: '0:15:00'
condition:
  - condition: device
    type: is_on
    device_id: 3889921153e8baec2a95442c97ec1e93
    entity_id: switch.shelly1_e8db84a93a46
    domain: switch
    for:
      hours: 1
      minutes: 0
      seconds: 0
      milliseconds: 0
action:
  - type: turn_off
    device_id: 3889921153e8baec2a95442c97ec1e93
    entity_id: switch.shelly1_e8db84a93a46
    domain: switch
mode: single

That code will trigger when the power drops from above 150W to below it, and stays there for 15 mins (not exceeding 150W) — and after that 15 mins, will check if the switch has been on for at least one hour. If it has, it’ll switch off; if not, it’ll give up and wait for the power to cross the threshold again.

If that’s not what you want, work out what you actually do want, and either describe it here or have a go at coding it yourself now you’ve explained it to the duck