Automation working fine, if triggers are not to long time apart

My goal is to turn on my waterheater, when my solarpanels are producing more that 1000W.
I did my automation i visual editor, and it works fine, if power from the panels drops below 1000W a few times a day. But if the sun is shining all day, the heater stays on after sunset.
The idea behind my automation is to turn on the heater if power is above 1000W - then wait 15 mins - turn off if power is below 1000W, or else turn on.
My issue is days when clouds lowers the power a few times during the day, the heater turn off after 15 mins, as it should. If power comes over 1000W it turns on again. Days with sun all day, the heater turns on, but does not turn off at the end of the day (when power comes below 1000W)
The code in YAML:

alias: Tænd vandvarmer
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.saj_current_power
    above: 1000
condition: []
action:
  - type: turn_on
    device_id: 483ceb8b126b3d8c111d7d51b61be757
    entity_id: 58a4370cedaa6188ce5c989c47ba3edc
    domain: switch
  - delay:
      hours: 0
      minutes: 15
      seconds: 0
      milliseconds: 0
    enabled: true
  - if:
      - condition: numeric_state
        entity_id: sensor.saj_current_power
        below: 999.9
    then:
      - type: turn_off
        device_id: 483ceb8b126b3d8c111d7d51b61be757
        entity_id: 58a4370cedaa6188ce5c989c47ba3edc
        domain: switch
    else:
      - type: turn_on
        device_id: 483ceb8b126b3d8c111d7d51b61be757
        entity_id: 58a4370cedaa6188ce5c989c47ba3edc
        domain: switch
mode: single

Forgive my spelling, as i`m Danish and newbee :slight_smile:

Your trigger is only triggering when you hit 1000W and it only will run when that happens - meaning if it’s 1000W for 12 hours then nothing triggers. You need a second trigger for falling below 1000W rather than an IF statement inside of your automation. Create two automations - one to turn it on and one to turn it off and I think it’ll work how you intend.

2 days ago, the heater was on for 52 mins - off for 20 mins - on for 1 hour and 23 mins - off for 57 mins, and so on. Why did it work then ?

My guess is that you dipped below 1000 and back up again, re-triggering your automation. Your automation is clear: do not run unless it’s below 1000 and goes over 1000 - no other time. Also you have a delay there, so your dipping below 1000 may have happened during the 15 minutes.

And as the sun goes down, power falls to 0, and still it wont turn off.
I`ll try to create 2 automations, and still keep the delay off 15 mins because of the idiotic rules in this country

You can do a second automation or you can create multiple triggers using ID’s in a single automation but the thing to know is that your automation is only like this because of you evaluating a NUMERIC condition, and when you do that you need a couple more failsafe methods in place if you want something to happen repeatedly.

Hmm…i must try to read up on this. It`s all new to me :slight_smile:
Thanks for your help so far :slight_smile:

Here’s something to work from:

alias: Tænd vandvarmer
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.saj_current_power
    above: 999
    id: Over 999
  - platform: numeric_state
    entity_id:
      - sensor.saj_current_power
    id: Under 1000
    below: 1000
  - platform: state
    entity_id:
      - switch.heater_entity
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 15
      seconds: 0
    id: Heater On 15 Minutes
condition: []
action:
  - if:
      - condition: trigger
        id:
          - Over 999
    then:
      - device_id: ""
        domain: ""
        entity_id: ""
    alias: Turn on Heater
  - alias: Turn off Heater
    if:
      - condition: trigger
        id:
          - Under 1000
    then:
      - device_id: ""
        domain: ""
        entity_id: ""
  - alias: Turn off Heater (Laws)
    if:
      - condition: trigger
        id:
          - Heater On 15 Minutes
    then:
      - device_id: ""
        domain: ""
        entity_id: ""
mode: single

You’ll need to fill in the actions on the conditions but that’s one automation for turning it on at 1000+, turning it off at <1000 and turning it off if it’s on 15 minutes. Quick and dirty so I didn’t add all the actions but once you paste that into the automation you’ll know what to do next.

Thanks, will try it tomorrow, as it`s 9.20 PM here :slight_smile:

Now i`ve tried this, and it seems to work fine:

alias: Tænd vandvarmer
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.saj_current_power
    above: 1000
    id: Over 1000
    for:
      hours: 0
      minutes: 5
      seconds: 0
  - platform: numeric_state
    entity_id:
      - sensor.saj_current_power
    below: 1000
    id: Under 1000
condition: null
action:
  - if:
      - condition: trigger
        id: Over 1000
    then:
      - type: turn_on
        device_id: 483ceb8b126b3d8c111d7d51b61be757
        entity_id: 58a4370cedaa6188ce5c989c47ba3edc
        domain: switch
        alias: Turn on Heater
  - if:
      - condition: trigger
        id: Under 1000
    then:
      - type: turn_off
        device_id: 483ceb8b126b3d8c111d7d51b61be757
        entity_id: 58a4370cedaa6188ce5c989c47ba3edc
        domain: switch
        alias: Turn off Heater
mode: single

1 Like

Well, it did not work as expected :frowning:


The heater has been off for at long time, even when the power was high.
Green mark on picture=ON, Red mark=OFF

It’s hard to see in that graph but it looks like the peaks that you thought should turn on the switch didn’t fire because your trigger says “over 1000 for 5 minutes” and looking at a couple of those that you expect to trigger it appears they may have dipped below 1000 during that 5 minute span.

I am a complete idiot. :joy:
You`re right, i thought i turned it ON for 5 mins…

We all start from somewhere and anyone can miss the obvious in stuff like this because it is so easy to do.

I think, making an automation in visual editor, and looking the YAML after, gives a better understanding on how it works. (for me)