Automation, I'm lost

I don’t get it anymore,
If I look at example automation.yaml files, mine looks the same.
But mine doesn’t work.

I am new to yaml, so if it could be a beginners mistake.

Here is my automations.yaml

 - alias: 'lamp_woonkamer'
# Lamp woonkamer
   trigger:
     - platform: sun
    # Possible values: sunset, sunrise
       event: sunset
    # Optional time offset. This example is 45 minutes.
       offset: '-00:30:00'
   action:
     - service: switch.turn_on
     - entity_id: switch.lamp_woonkamer

 - alias: 'luchtverfrisser_uit'
# Luchtverfrisser uit
   trigger:
     - platform: time
    # When 'at' is used, you cannot also match on hour, minute, seconds.
    # Military time format.
       at: '22:32:00'

   action:
     - service: switch.turn_off
     - entity_id: switch.luchtverfrisser
 
 - alias: luchtverfrisser_aan
# Luchtverfrisser aan 
   trigger:
     - platform: time
    # When 'at' is used, you cannot also match on hour, minute, seconds.
    # Military time format.
       at: '09:32:00'
    
   action:
     - service: switch.turn_on
     - entity_id: switch.luchtverfrisser
    
 - alias: luchtverfrisser_niet_thuis
   trigger:
     - platform: state
       entity_id: device_tracker.phone_phone, device_tracker.kim_greatlte
    # Optional
       from: 'home'
    # Optional
       to: 'not_home'

    # If given, will trigger when state has been the to state for X time.
       for:
       seconds: '/5'
   action:
      - service: switch.turn_off
      - entity_id: switch.luchtverfrisser

And my HA returns:

We can’t see what your HA returns. :slight_smile:
I think when you remove the hyphens in front of the entity_id’s it should work.

   action:
     - service: switch.turn_on
       entity_id: switch.lamp_woonkamer
1 Like

It is really easy to make a simple mistake in the yaml file.
http://yaml-online-parser.appspot.com or similar tool is your friend.

That worked…! Thanks a lot

I used Yamllint for that, and it gave me a “Valid YAML!” back, but HA didn’t like it though.

Still lost with automation and yaml. The more I read, the more I’m confused.
Back in the day when I wrote in Cobol and RPG3 I had documentation telling me what belongs in which column, with yaml I can’t find something like that.

I’m trying to detect my tasmota devices for wich I have to set option 19 to 1. Works fine in the web console and should be doable via an automation in hass, too.

Here is the example from tasmota github:

- alias: "Enable MQTT discovery for all devices"
  trigger:
    platform: homeassistant
    event: start
  action:
    - service: mqtt.publish
      data:
        topic: "sonoffs/cmnd/SetOption19"
        payload: "1"  

I tried several versions with different indention with and without hyphens and get different error messages.

Closest I got (at least hass loads)

 alias: "Enable MQTT discovery for all devices"
 trigger:
   - platform: homeassistant
     event: start
 action:
   - service: mqtt.publish
   - data:
     topic: "sonoffs/cmnd/SetOption19"
     payload: "1"

There I get following errors:

    2019-03-19 15:37:43 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: expected dict for dictionary value @ data['action'][1]['data']. Got None
extra keys not allowed @ data['action'][1]['payload']. Got '1'
extra keys not allowed @ data['action'][1]['topic']. Got 'sonoffs/cmnd/SetOption19'. (See /home/homeassistant/.homeassistant/configuration.yaml, line 73). Please check the docs at https://home-assistant.io/components/automation/

Line 73 of configuration.yaml being the line where automations.yaml is included.

Can somebody point me in any direction where I can find documentation about what goes where with or without hyphen? For instance, in automation documentation alias is used with a hyphen and in automation 2 doc it is used without.

Thanks for listening to my grief :smiley:

Edited for proper formating.

Help us help you. Please format your automations so that all indentation is properly displayed. Otherwise we are obliged to decipher your unformatted automation … and that’s no fun.

Use the instructions shown in the banner at the top of the page. Alternately, use markdown’s code-blocks which is to simply add three backticks ``` before and after your code.

The indention looks like I have it here, used the “preformated text” for it. I used multiples of two spacing. I’ll try again …