What's wrong with this since latest update?

This is one of the automations that was working before last update :anguished:

- id: '1579308787838'
  alias: Laundry room lights
  description: ''
  trigger:
  - entity_id: binary_sensor.shenzhen_neo_electronics_co_ltd_battery_powered_pir_sensor_sensor_3
    platform: state
  action:
  - entity_id: switch.laundry_room_main_lights
  service_template: |-
  {% if trigger.to_state.state == 'on' %}
    switch.turn_on
  {% else %}
    switch.turn_off
  {% endif %}

Tried moving quotes etc around but still unsupported action…

Now I get from the logs :
Error loading /config/configuration.yaml: while scanning for the next token found character ‘%’ that cannot start any token in “/config/automations.yaml”, line 10, column 4

6:34 PM components/hassio/init.py (ERROR) - message first occurred at 6:01 PM and shows up 4 times

while scanning for the next token found character ‘%’ that cannot start any token in “/config/automations.yaml”, line 10, column 4

6:34 PM util/yaml/loader.py (ERROR) - message first occurred at 6:01 PM and shows up 4 times

I dont see how it ever worked. It is incorrectly indented. The service template should not be at the same level as the action block. Corrected:

  action:
  - entity_id: switch.laundry_room_main_lights
    service_template: |-
      {% if trigger.to_state.state == 'on' %}
        switch.turn_on
      {% else %}
        switch.turn_off
      {% endif %}

Changed the indentation. Now:
Invalid config for [automation]: [action] is an invalid option for [automation]. Check: automation->trigger->0->action. (See /config/configuration.yaml, line 13).

Might be wrong binary sensor, let me check.

should that not be

service_template: >-

Yep, but I also agree with Tom, ‘that’ never worked

yep. never worked.

Backstory:

Saved everything to text file on local computer, had issues with NUC. Reinstalled everything, copied and pasted configuration.yaml. I’m by far just scraping the bottom of noob with this stuff. Corrected indentations, everything working now. Thank you guys very much.

2 Likes

Let me ask another question on top of this thread. If I wanted to add a time duration it should look like:

- id: '1579308787838'
  alias: Laundry room lights
  description: ''
  trigger:
  - entity_id: binary_sensor.shenzhen_neo_electronics_co_ltd_battery_powered_pir_sensor_sensor_3
    platform: state
  action:
  - entity_id: switch.laundry_room_main_lights
    service_template: >-
      {% if trigger.to_state.state == 'on' %}
        switch.turn_on
         for:
         minutes: 5
      {% else %}
        switch.turn_off
      {% endif %}

Correct?

Incorrect. There is no for option for that service and service template results need to be a single line.

Also even if it was valid, as soon as your movement sensor state changes to off the light will still turn off.

It seems that you are trying to create a timed motion activated light. This is the best way:

https://www.home-assistant.io/cookbook/turn_on_light_for_10_minutes_when_motion_detected/

Tom, thank you. Is there a reference I can use when trying to create automations, with all the variables, etc? I’ve been looking at YAML websites, but I can’t find anything all-inclusive.

perhaps try the GUI editor and then check the created yaml code after for hints. It will also not let you write stuff that is invalid. Many people will disagree with this as there’s a lot of hate for the GUI editor but it’s gotten a bad rap IMO.

Basic YAML Primer: http://thomasloven.com/blog/2018/08/YAML-For-Nonprogrammers/

Then pick some topics in the right hand menu of the Home Assistant Docs and read/experiment/read again.

1 Like

So informative. Bookmarked, will be referencing. Thank you.