Just a simple random on and off during certain hours for one light?

Thanks for the quick response Taras.
I was starting the automation manually to run as a test (hence the 1,5 minute random numbers). Apparently, turning it on that way did not have a trigger id which I believe caused the failure.
This morning it started at the appropriate time and seems to be working on it’s own.

So bottom line, it can’t be triggered manually. If I stop it to make changes, it probably won’t work until tomorrow (or at turn_off at the off time). So it would be nice to have a trigger_id of ‘default’ in case the system gets restarted during the allowed times. I’ll have to come up with something for that but I don’t know what yet.

Cheers

I have similar request. My light was connected to a smart plug. I set 2 automatic task. one is turn on light when sun senor dusk. the next I tried to do is turn off the light near 11pm. I tried using GUI to create the task. I really like to turn off the light ramdonly between 10:50-11:30pm. After reading this topic, I tried following. but failed. Any experienced guru can help to correct my script?

the orginial set time one is here.
alias: turn off light before mid night
description: “”
trigger:

  • platform: time
    at: “22:55:00”
    condition:
    action:
  • service: script.turn_off_p110_plug
    data: {}
    mode: single

This will turn off light exactly at 10:55pm.

I tried to modify as below
alias: turn off light before mid night
description: “”
trigger:

  • platform: state
    entity_id: switch.smart_plug_p110
    to:
    for:
    minutes: “{{ range(10,30)|random }}” # 10 to 30 minutes feel free to change
    condition:
  • condition: time
    after: “22:55”
    before: “23:30”
    action:
  • service: script.turn_off_p110_plug
    data: {}
    entity_id: switch.smart_plug_p110
    mode: single

HA script can be saved. Test run the script turns off the light. However, the actual run doesn’t do anything. Any problem of the script?

https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371#oneone-format-it-properly-16

EDIT: oops. Sorry did not realise that was a two month old post. I was here looking at something else when I saw it.

1 Like