Turning off a nightlight

Hi All,

I have been trying to get some scripts working to turn on a nightlight and automatically turn off after 10 minutes for the three last days. Everything is working, except the delay script isn’t actually turning of the light.

I’ve been searching this forum and google for the last three days, but still I can’t see what I’m doing wrong. So as a last resort I’m post the code here and hope that somebody can see what my mistake is.

Since I haven’t got any physically PIR and lights yet, I’m only using mosquitto_sub and mosquitto_pub as my test harness. I don’t know if this should have an impact on the result, since a timed action to turn of the light is working flawlessly.

I’m testing this on a Linux PC.

The scripts I’m using is divided into single files, since this makes most sense to me, and is shamelessly copied from user Brusc on [Github] (https://github.com/brusc/Home-Assistant-Configuration) and the example here on Home assistant.

Automation script, works perfectly:

alias: "motion light during night time"
trigger:
  platform: state
  entity_id: sensor.hallway_motion
  state: "motion detected"
action:
- service: script.turn_on
  data:
    entity_id: script.motion_bathroom

Motion Bathroom, works perfectly:

alias: "Turn on lamp and set timer"
sequence:
- service: script.turn_off
  data:
    entity_id: script.motion_bathroom_timer
- service: homeassistant.turn_on
  data:
    entity_id: light.rgb_lys_gang
    rgb_color: [255,0,0]
- service: script.turn_on
  data:
    entity_id: script.motion_bathroom_timer

Motion bathroom timer
In the logbook I can see that this script turns on and then turns off again after exactly 10 minutes, but the service (action?) seems not to be executed.

alias: "Turn off lamp after 10 minutes"
sequence:
- delay:
    minutes: 10
- service: homeassistant.turn_off
  data:
    entity_id: light.rgb_gang_lys

Best regards,
Peo

An errors in the console during startup or executing of the scripts?

Thank you for replying.

Nope, no errors in the console or the log file.

Hmm, strange that you not getting any errors.
But I think I see a mistake in Motion bathroom timer: Should it be rgb_lys_gang instead of rgb_gang_lys?

I thought it might be a stupid mistake… and I was right! :flushed:

I will change this and try again.

Thank you for your help!

Peo

EDIT:

Now it works!!! :grin:

I’m a little suprised that I never got an error message, saying that the sensor wasn’t found, but now I know not to trust the error messages only…