Simple on delay off automation changing time on me (shellypro)

Hi, I have Home assistant running inside docker on my home server.
It’s not doing too much but one of things i need it to do is make sure i have hot water.

I have a shelly pro with this automation:

alias: Hot Water Timer on at 11 off at 16
description: >-
  There is a Shelly Pro wifi relay breaker in the fuseboard connected to the the
  3600W hot water boiler.

  During the day from 11am it is anticipated that there will be enough solar
  energy available to heat the boiler. 

  It is estimated the boiler will need to run for three hours. I'm making it
  16:00 to be safe.
trigger:
  - platform: time
    at: "11:00:00"
condition: []
action:
  - type: turn_on
    device_id: 2dcd34aa0d91561d01195bc387b5f8aa
    entity_id: switch.wifi_smart_timer_socket_1
    domain: switch
  - delay:
      hours: 4
      minutes: 0
      seconds: 30
      milliseconds: 0
  - type: turn_off
    device_id: 2dcd34aa0d91561d01195bc387b5f8aa
    entity_id: switch.wifi_smart_timer_socket_1
    domain: switch
mode: restart

This exists becuase i have solar panels and i want to heat the water for a set window each day.
all has been working for months, no issue at all. then we started noticing we were running out of hot water. I can’t find anything odd in the logbook, but when i go to history i see this:

so i don’t understand:
Why is the automation not delaying for 4 hours on some days.
Why does the history only go back a week?

ok, looking at this a bit more, the automation yaml script doesn’t match
in the automation yaml the id
device_id: 2dcd34aa0d91561d01195bc387b5f8aa
entity_id: switch.wifi_smart_timer_socket_1
don’t match the log which lists the device as
switch.shellyprohwtimer_switch_0

so maybe the timer routine is in the shelly itself?
i’m very confused.

i did replace an old tuya relay with this shelly some months ago.

Delaying for hours is never a good idea. And why is it mode: restart?
Here is how I would do it:

alias: Hot Water Timer on at 11 off at 16
description: >-
  There is a Shelly Pro wifi relay breaker in the fuseboard connected to the the
  3600W hot water boiler.

  During the day from 11am it is anticipated that there will be enough solar
  energy available to heat the boiler. 

  It is estimated the boiler will need to run for three hours. I'm making it
  16:00 to be safe.
trigger:
  - platform: time
    at: "11:00:00"
    id: on
  - platform: time
    at: "16:00:00"
    id: off
condition: []
action:
  - action: "switch.turn_{{ trigger.id }}"
    metadata: {}
    data: {}
    target:
      entity_id: switch.wifi_smart_timer_socket_1
mode: single

Thanks Hellis,
It was so long ago i can’t remember why it was set up like that. I’m pretty sure it was copypasta and this made sense to me.
Thanks for you example, thought i don’t understand how it knows to turn on or off.
I will go and do some reading on the yaml script.
Thanks again!

hmmmm so i can’t quite get this, when i try i get an error about data: {}
apparently i can’t use an inline template?

anyway, this is what i did

alias: Hot Water Timer on at 11 off at 16
description: >-
  There is a Shelly Pro wifi relay breaker in the fuseboard connected to the
  3600W hot water boiler.

  During the day from 11am it is anticipated that there will be enough solar
  energy available to heat the boiler. 

  It is estimated the boiler will need to run for three hours. I'm making it
  16:00 to be safe.
trigger:
  - platform: time
    at: "11:00:00"
    id: "on"
  - platform: time
    at: "16:00:00"
    id: "off"
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: "on"
        sequence:
          - service: switch.turn_on
            data: {}
            target:
              entity_id: switch.shellyprohwtimer_switch_0
      - conditions:
          - condition: trigger
            id: "off"
        sequence:
          - service: switch.turn_off
            data: {}
            target:
              entity_id: switch.shellyprohwtimer_switch_0
mode: single

Sure you can… I have that in many automation.

If there is one potential issue I spot in the example code from @Hellis81 above, it is that there are no quotes around “on” and “off”. This would typically make HASS interpret them as boolean true / false, which probably are not valid values for id which expects a string.

Try adding quotes around them and it may work, or change the ids themselves to be the full turn_on / turn_off (and modify the action template accordingly).

thanks, it’s still not working. we got 36 minutes of hotwater then it turned off.
the logbook says:



Hot Water Timer on at 11 off at 16 triggered by time

11:00:00 - 10 hours ago - Traces


ShellyProHWTimer switch_0 turned on triggered by automation Hot Water Timer on at 11 off at 16 triggered by time

11:00:00 - 10 hours ago

ShellyProHWTimer switch_0 turned off

11:36:52 - 9 hours ago

then later at 4pm


Hot Water Timer on at 11 off at 16 triggered by time

16:00:00 - 5 hours ago - Traces

The logbook doesn’t say what turned it off, there are no other automations and i checked the the shelly unit itself doesn’t have a schedule.
I’ve updated the shelly firmware
I havn’t doubled checked but i think it’s turning off early to the second, which would indicate some sort of configuration or automation rather than an overheat or drop out.

Should i delete it from home assistant and see if i can get it working just locally in shelly? see if it still turns off?

There must be something else controlling it.
When switched off there is no mention of an automation.
Check if the plug itself has some automation in Shelly app or webUI.