My script stopped working

Script has been working fine before, some functions just stopped working.

lyspaamorgen:
   alias: lys_paa_google
   sequence:
   - alias: lys soverom paa
     service: light.turn_on
     data:
      entity_id: light.soverom
   - alias: lys paa
     service: light.turn_on
     data:
      entity_id: group.lys_gang_kjokken_stue
      brightness: 30
   - alias: lys paa bad
     service: switch.turn_on
     data:
      entity_id: switch.fibaro_system_fgs213_switch_switch_4
   - alias: varme sov av
     service: switch.turn_off
     data:
      entity_id: switch.varme_soverom
   - alias: mediaplayer_volum_set
     service: media_player.volume_set
     data:
       entity_id: media_player.stue
       volume_level: 0.30  
   - alias: mediaplay_spill_musikk  
     service: media_player.play_media
     entity_id: media_player.stue
     data:
       media_content_id: http://lyd.nrk.no/nrk_radio_mp3_mp3_m
       media_content_type: audio/mp4
   - alias: Slaa_paa_tv_stasjon
     service: switch.turn_on
     entity_id: switch.el_stue
   - delay: '00:05:00'
   - alias: lys soverom av
     service: light.turn_off
     data:
      entity_id: light.soverom

Looks like the script stops in the middle, it does all commands until the switch.varme_soverom command. That command and all other below does not work.

What could be wrong?

I don’t think alias is part of the standard config and definitely isn’t needed.

Drop all the alias lines and make a list of the service call chunks.

Also check your indentations. It is hard to tell on my phone but it looks like there are some inconsistencies. Also be consistent using data before the entity is line.

1 Like

Thank you @silvrr , but still same problem.

Cleaned up the code a bit:

lyspaamorgen:
    sequence:
      - service: light.turn_on
        data:
          entity_id: light.soverom

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

      - service: switch.turn_on
        data:
          entity_id: switch.fibaro_system_fgs213_switch_switch_4

      - service: switch.turn_off
        data:
          entity_id: switch.varme_soverom

      - service: media_player.volume_set
        data:
          entity_id: media_player.stue
          volume_level: 0.30  

      - service: media_player.play_media
        data:
          entity_id: media_player.stue
          media_content_id: http://lyd.nrk.no/nrk_radio_mp3_mp3_m
          media_content_type: audio/mp4

      - service: switch.turn_on
        data:
          entity_id: switch.el_stue

      - delay: '00:05:00'

      - service: light.turn_off
        data:
          entity_id: light.soverom

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.

Hmm, spacing looks correct and the script should be written correctly, anything in the logs after you try and run this script?

Everything looks correct. Can you confirm that all entities in group.lys_gang_kjokken_stue are capable of having their brightness set? Maybe something fails in this operation and that’s why the sequence stops there?

I agree with @silvrr and you should check the log for errors, warnings, etc.

@123 & @silvrr - thank you guys! :slight_smile:

Just checked log, this is what I found after running the script:

Log Details (ERROR)
Wed Dec 05 2018 16:48:04 GMT+0100 (sentraleuropeisk normaltid)

Error executing service <ServiceCall switch.turn_on (c:1d3ef01eaa8c4077ba6091e281dadccc): entity_id=['switch.fibaro_system_fgs213_switch_switch_4']>
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/core.py", line 1177, in _event_to_service_call
    await service_handler.func(service_call)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_component.py", line 177, in handle_service
    self._platforms.values(), func, call
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/service.py", line 250, in entity_service_call
    permission=POLICY_CONTROL
homeassistant.exceptions.Unauthorized: Unauthorized

Does this switch work when toggled manually on the front end?

Double check the entity_id in the states page.

Yes it works fine when toggled. And the entity_id is correct. Strange

I searched the forum for POLICY_CONTROL https://community.home-assistant.io/search?q=POLICY_CONTROL

You are not the only person who has experienced this problem and it seems to be related to changes in 0.83.X.

thank you so much for that information. I will look into similar cases :slight_smile:

Anyone found a solution to make this work?

When I try to run my scripts via Google home it still does not run the complete script, it stops in the middle. I get a notification “Login attempt or request with invalid authentication from 3.81.8.xx”

Hmm i have the same problem.
My Bedtime script which is triggered via IFTTT suddenly stopped working. Has been working for years. Now works when triggered locally but not via IFTTT web hook. Long list errors in log ending with
File “/usr/local/lib/python3.6/site-packages/homeassistant/helpers/service.py”, line 250, in entity_service_call
permission=POLICY_CONTROL
homeassistant.exceptions.Unauthorized: Unauthorized

I am using API password in the call. Should i be using a user instead somehow ? Any suggestions welcome, facing severe WAF backlash. :frowning:

I am running on a windows 10 > oracle virtual box > ubuntu > hass in case that has something to do with it

Anyone that could assist us here?

Same here, looks like API_PASSWORD is not supported anymore. You have to use long-lived access tokens now which is really a bummer because I have a lot of Tasker tasks firing off all kinds of scripts, automations and entities. Will try to add these with a Tasker variable I guess.

Update:
Well that was pretty easy actually :).
I created a global variable %HASSTOKEN and entered the token there. Then I changed my HTTP Post commands from (example):

https://MYDOMAIN.duckdns.org/api/services/script/turn_on?api_password=MYPASSWORD

to:

https://MYDOMAIN.duckdns.org/api/services/script/turn_on?authSig=%HASSTOKEN

And everything is working again :).

For IFTTT you have to change ?api_password=MYPASSWORD into ?authSig=VERYLONGTOKEN
UPDATE: This is not working for IFTTT.

1 Like

don’t know if your issue is still present, but you could leave out all data: blocks for entities that don’t use any extra data.

in this case just state:

- service: switch.turn_on 
  entity_id: switch.fibaro_system_fgs213_switch_switch_4

and do so for all other entities that don’t use extra data.

Might not help, otoh, its the first entry in your script that stops, so might be worth a try.