Start automation only if script has been trigged for a little time ago

I am running a “good night” script from Google home. For some reason it will not run the full script after the new HA updates, so I need to add another automation to make this work.

I want this automation to turn off all lights in my house. For this to work, it will need it to work only after the script (script.lysavnatt) has been triggered manually, and second trigger when the motion detector has been triggered. After motion detector has been triggered it should activate the “sleep” scene after 10 minutes.

  1. I will run the “good night” script from google home.
  2. When the script (script.lysavnatt) has been activated it will activate a timer after the motion detector (binary_sensor.neo_coolcam_battery_powered_pir_sensor_sensor_2) has been triggered.
  3. After 10 minutes a scene should be turned on (scene.all_lys_av).

I am not sure if I need an input boolean for this, or maybe there is a easier way? Anyone with a good idea? :smiley:

Post the script so we can work out why it isn’t running rather than overcomplicating things :slight_smile:

Sure, here it is :slight_smile:

lysavnatt:
   alias: lys_av_google
   sequence:
    - alias: dim_lys_natt
      service: scene.turn_on
      entity_id: scene.stuekjokkengang_minimum_lys
    - alias: lys_paa
      service: light.turn_on
      data:
       entity_id: light.soverom
       brightness: 5 
    - alias: Slaa_av_tv
      service: switch.turn_on
      entity_id: switch.switch_harmony_off
    - alias: Slaa_paa_lys_bad
      service: switch.turn_on
      entity_id: switch.fibaro_system_fgs213_switch_switch_4
    - alias: mediaplayer_volum_set2
      service: media_player.volume_set
      data:
       entity_id: media_player.stue
       volume_level: 0.30  
    - delay: '00:10:00'
    - alias: Slaa_av_tv_stasjon
      service: switch.turn_off
      entity_id: switch.el_stue
    - alias: Lys_kjokken_av
      service: light.turn_off
      entity_id: light.fibaro_system_fgd212_dimmer_2_level_5
    - alias: Lys_gang_av
      service: light.turn_off
      entity_id: light.fibaro_system_fgd212_dimmer_2_level_6
    - alias: Lys_bad_speil_av
      service: switch.turn_off
      entity_id: switch.fibaro_system_fgs213_switch_switch_4
    - alias: Lys_stue_av
      service: light.turn_off
      entity_id: light.fibaro_system_fgd212_dimmer_2_level_4
    - delay: '00:01:00'
    - alias: lys av soverom
      service: light.turn_off
      data:
       entity_id: light.soverom
    - alias: Slaa_av_vifte_bad
      service: switch.turn_off
      entity_id: switch.fibaro_system_fgs213_switch_switch_3

And this is the error I get after running this script via google home

Log Details (WARNING)

Thu Dec 27 2018 12:45:32 GMT+0100 (sentraleuropeisk normaltid)

Login attempt or request with invalid authentication from 3.83.226.202

How far in the script does it get?

This is the last sequence that works:

- service: light.turn_on
            data:
              entity_id: group.lys_gang_kjokken_stue
              brightness: 30

Everything after that in the code does not run. What could cause this? And also this worked just fine before, just stopped working.

That command isn’t in the script you post :confused:

I am sorry, this is the last one that I can see is working:

- alias: Slaa_paa_lys_bad
  service: switch.turn_on
  entity_id: switch.fibaro_system_fgs213_switch_switch_4

Try commenting out the volume set and delay beneath that and see if it gets to the end, or at least a bit farther.

Tried commenting out volume set and other elements, but the script did not continue…

I also get this login attempt failed warning every time i try to run the script.

I don’t know why you would get an invalid login from running a script that switches a few things on and off. Something else is afoot here I think :confused:

Anything to do with the harmony API changes last week ?

Ooooh, possibly. Not sure, don’t run a harmony :slight_smile:

Neither do I.
Just throwing it out there :stuck_out_tongue_winking_eye:

1 Like

I removed the harmony sequence also, still same problem.

This problem with scripts starting via Google Home came with the last big upgrade of HA. It worked perfect before, but when it was updated something changed. Thats why I was thinking just to make another automation to get around the problem :slight_smile:

But does it work if you activate the script from the interface?

just tried manually, works fine then. no problem at all. so the problem is when starting it via google home

OK, needs reporting as a bug then :slight_smile:

As a workaround, try getting GH to switch an input boolean on, use that going on to trigger the script and then turn the boolean off again ready for next time.

1 Like

I might be off base here but…

Why do you have all of those extra "-alias: " lines nested inside the script?

  lysavnatt:
   alias: lys_av_google
   sequence:
    **- alias: dim_lys_natt**
      service: scene.turn_on
      entity_id: scene.stuekjokkengang_minimum_lys
    **- alias: lys_paa**
      service: light.turn_on
      data:
       entity_id: light.soverom
       brightness: 5 
    **- alias: Slaa_av_tv**
      service: switch.turn_on
      entity_id: switch.switch_harmony_off
    **- alias: Slaa_paa_lys_bad**
      service: switch.turn_on
      entity_id: switch.fibaro_system_fgs213_switch_switch_4
      .
      .

That might be the problem as I’ve never seen that done before.

It is valid, albeit a bit pointless IMO. And given that it works fine when it is run from the UI my educated guess would be that GH is turning the script back off again part way through its run.