Automation - Delay issue

Hi,

delay does not seem to work as expected. Well kind of. The following example works perfectly fine after HA is restarted (switch is turned off after being on for 3h (03:00:00)), but the following day it’s only on for 3m.

- alias: Test switch on
  trigger:
    platform: sun
    event: sunset
    offset: '+00:00:00'
  action:
    - service: switch.turn_on
      entity_id: bla
    - delay: '03:00:00'
    - service: switch.turn_off
      entity_id: bla

Thanks.

It looks ok to me, but I am fairly new to this. You don’t have another automation that might be in conflict?
Perhaps you could try to write the time like below and see if it works better?

action:
  - service: homeassistant.turn_on
    entity_id: bla
  - delay:
      hours: 3
  - service: homeassistant.turn_off
    entity_id: bla

That’s what I am going to try next (which would be a workaround then) … I’ll let you know how it went.

Using delay and hours also does not work :frowning:

17-03-22 18:27:08 INFO (MainThread) [homeassistant.components.automation] Executing TEST sunset power
17-03-22 18:27:08 INFO (MainThread) [homeassistant.core] Bus:Handling <Event logbook_entry[L]: domain=automation, entity_id=automation.test_<HM_Device>_an_wenn_sonnenuntergang, name=TEST sunset power, message=has been triggered>
17-03-22 18:27:08 INFO (MainThread) [homeassistant.helpers.script] Script TEST sunset power: Running script
17-03-22 18:27:08 INFO (MainThread) [homeassistant.helpers.script] Script TEST sunset power: Executing step call service

17-03-22 18:27:08 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_call_id=1971714480-35, service=turn_on, service_data=entity_id=[‘switch.<HM_Device>’], domain=switch>

17-03-22 18:27:08 DEBUG (Thread-13) [pyhomematic.devicetypes.generic] HMDevice.event: Using callback <bound method HMSwitch._hm_event_callback of <Entity <HM_Device>: off>>
17-03-22 18:27:08 DEBUG (Thread-13) [homeassistant.components.homematic] <HM_Device> received event ‘STATE’ value: True
17-03-22 18:27:08 DEBUG (Thread-13) [homeassistant.components.homematic] <HM_Device> update_ha_state after ‘STATE’
17-03-22 18:27:08 DEBUG (Thread-13) [pyhomematic.devicetypes.generic] HMDevice.event: Using callback <bound method HMSwitch._hm_event_callback of <Entity <HM_Device>: on>>
17-03-22 18:27:08 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state switch.<HM_Device>=on; proxy=wireless, id=, friendly_name=<HM_Device>, working=No, rssi=-64 @ 2017-03-22T18:27:08.874608+01:00>, old_state=<state switch.<HM_Device>=off; proxy=wireless, id=, friendly_name=<HM_Device>, working=No, rssi=-64 @ 2017-03-21T22:28:45.592466+01:00>, entity_id=switch.<HM_Device>>
17-03-22 18:27:08 DEBUG (Thread-13) [homeassistant.components.homematic] <HM_Device> received event ‘WORKING’ value: False
17-03-22 18:27:08 DEBUG (Thread-13) [pyhomematic.devicetypes.generic] HMDevice.event: Using callback <bound method HMSwitch._hm_event_callback of <Entity <HM_Device>: on>>
17-03-22 18:27:08 DEBUG (Thread-13) [homeassistant.components.homematic] <HM_Device> received event ‘STATE’ value: True
17-03-22 18:27:08 INFO (MainThread) [homeassistant.helpers.script] Script TEST sunset power: Executing step call service

17-03-22 18:27:10 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state automation.test_<HM_Device>an_wenn_sonnenuntergang=on; friendly_name=TEST sunset power, last_triggered=2017-03-22T18:27:10.378368+01:00 @ 2017-03-21T13:54:31.041468+01:00>, old_state=<state automation.test<HM_Device>an_wenn_sonnenuntergang=on; friendly_name=TEST sunset power, last_triggered=2017-03-21T18:27:10.264459+01:00 @ 2017-03-21T13:54:31.041468+01:00>, entity_id=automation.test<HM_Device>an_wenn_sonnenuntergang>
17-03-22 18:28:44 INFO (MainThread) [homeassistant.components.automation] Executing TEST sunset power
17-03-22 18:28:44 INFO (MainThread) [homeassistant.core] Bus:Handling <Event logbook_entry[L]: domain=automation, entity_id=automation.test
<HM_Device>_an_wenn_sonnenuntergang, name=TEST sunset power, message=has been triggered>
17-03-22 18:28:44 INFO (MainThread) [homeassistant.helpers.script] Script TEST sunset power: Executing step call service

17-03-22 18:28:44 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_call_id=1971714480-37, service=turn_off, service_data=entity_id=[‘switch.<HM_Device>’], domain=switch>

17-03-22 18:28:44 DEBUG (Thread-13) [pyhomematic.devicetypes.generic] HMDevice.event: Using callback <bound method HMSwitch._hm_event_callback of <Entity <HM_Device>: on>>
17-03-22 18:28:44 DEBUG (Thread-13) [homeassistant.components.homematic] <HM_Device> received event ‘STATE’ value: False
17-03-22 18:28:44 DEBUG (Thread-13) [homeassistant.components.homematic] <HM_Device> update_ha_state after ‘STATE’
17-03-22 18:28:44 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state switch.<HM_Device>=off; proxy=wireless, id=, friendly_name=<HM_Device>, working=No, rssi=-64 @ 2017-03-22T18:28:44.842475+01:00>, old_state=<state switch.<HM_Device>=on; proxy=wireless, id=, friendly_name=<HM_Device>, working=No, rssi=-64 @ 2017-03-22T18:27:08.874608+01:00>, entity_id=switch.<HM_Device>>
17-03-22 18:28:44 DEBUG (Thread-13) [pyhomematic.devicetypes.generic] HMDevice.event: Using callback <bound method HMSwitch._hm_event_callback of <Entity <HM_Device>: off>>
17-03-22 18:28:44 DEBUG (Thread-13) [homeassistant.components.homematic] <HM_Device> received event ‘WORKING’ value: False
17-03-22 18:28:44 DEBUG (Thread-13) [pyhomematic.devicetypes.generic] HMDevice.event: Using callback <bound method HMSwitch.hm_event_callback of <Entity <HM_Device>: off>>
17-03-22 18:28:44 DEBUG (Thread-13) [homeassistant.components.homematic] <HM_Device> received event ‘STATE’ value: False
17-03-22 18:28:44 INFO (MainThread) [homeassistant.helpers.script] Script TEST sunset power: Executing step call service
17-03-22 18:28:46 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state automation.test
<HM_Device>an_wenn_sonnenuntergang=on; friendly_name=TEST sunset power, last_triggered=2017-03-22T18:28:46.431046+01:00 @ 2017-03-21T13:54:31.041468+01:00>, old_state=<state automation.test<HM_Device>an_wenn_sonnenuntergang=on; friendly_name=TEST sunset power, last_triggered=2017-03-22T18:27:10.378368+01:00 @ 2017-03-21T13:54:31.041468+01:00>, entity_id=automation.test<HM_Device>_an_wenn_sonnenuntergang>

Ideas?