Homeassistant.turn_on in a script gives me "homeassistant.turn_off cannot be called without a target" but target is set

Hi There
I have this script:

shutdown_button_on:
  alias: shut down home
  sequence:
  - service: media_player.turn_off
    data:
      entity_id: media_player.speakerbureau, media_player.speakerkitchen, media_player.speakersleeping,
        media_player.speakerliving, media_player.speakerhall
  - service: homeassistant.turn_off
    data:
      entity_id: group.lights_living
  - service: homeassistant.turn_off
    data:
      entity_id: group.lights_kitchen
  - service: homeassistant.turn_off
    data:
      entity_id: group.lights_downstairs
  - service: script.turn_on
    entity_id: script.vsx_s300_power_off
  mode: single

HASS does not turn off the groups; the log tells me:

2020-12-21 21:53:14 ERROR (MainThread) [homeassistant.components.homeassistant] homeassistant.turn_off cannot be called without a target
2020-12-21 21:53:14 ERROR (MainThread) [homeassistant.components.homeassistant] homeassistant.turn_off cannot be called without a target
2020-12-21 21:53:14 ERROR (MainThread) [homeassistant.components.homeassistant] homeassistant.turn_off cannot be called without a target

hass --script check_config -c ... cant find anything. I checked the docs (see here for example: Home Assistant Core Integration - Home Assistant).
Can’t I use homeassistant.turn_off in a script? It’s not mentioned anywhere as far as I have seen…

Another question: When do I have to use “data:”? Sometimes it’s there in the docs another time it’s not.

Hint: All groups exist an do have entities in it. The groups are read only in the UI-configurator, because the do not have a unique_id. Perhaps its related.

Thanks for your help.

Try this…

shutdown_button_on:
  alias: shut down home
  sequence:
    - service: homeassistant.turn_off
      entity_id:
        - media_player.speakerbureau
        - media_player.speakerkitchen
        - media_player.speakersleeping
        - media_player.speakerliving
        - media_player.speakerhall
        - group.lights_living
        - group.lights_kitchen
        - group.lights_downstairs
    - service: script.turn_on
      entity_id: script.vsx_s300_power_off

Tried this. No output to the log and HASS does nothing. In the original config posted above, the mediaplayers stopped. When the script came to the homassistant.turn_off it threw an error message about no target.

When I config a script with the UI-configurator the configurator does not show any available entites for the service homeassistant.turn_on/turn_off… I guess the problem is locate with the homeassistant domain somehow…

Most annoying: nothing in the log file even with debugging for script component activated.

Problem solved: One entity had “-” in it that i copied from the UI… “-” are not allowed, only “_”. No hint from the config checker or the debug log. But after restarting, HASS complained about not setting up the group domain. Et voila, issue was located.

So symptoms were: no entities to choose from in the UI-configurator, ambigous error “homeassistant.turn_off cannot be called without a target”, no debug output from script component, script checker did not show the error. Solution: check entity naming and especially do not use “-” in entity names.

Thanks to @anon43302295 for cleaning up my testscript, appreciated your efforts! Have a good one and thanks again.

1 Like