Cannot automate button with yeelight

Hello, i am trying to write my first automation and having some difficulties. I have a aqara button (round one) and I want to connect my yeelight to toggle on / off on click. I have following code (automations.yaml),

     - alias: 'Turn on bed room lights'
trigger:
  platform: event
  event_type: click
  event_data:
  entity_id: binary_sensor.switch_158d0001e822ab
  click_type: single

action:
- service: light.turn_on
data:
  entity_id: 
    - light.tv_light

But I get following error which doing check config. When I remove the above code from automations file then evenythink works fine.

Configuration invalid

Invalid config for [automation]: expected dict for dictionary value @ data[‘trigger’][0][‘event_data’]. Got None
extra keys not allowed @ data[‘data’]. Got None
extra keys not allowed @ data[‘trigger’][0][‘click_type’]. Got None
extra keys not allowed @ data[‘trigger’][0][‘entity_id’]. Got None. (See /config/configuration.yaml, line 110). Please check the docs at https://home-assistant.io/components/automation/

A good starting point would be to read the blue box on top of this topic and edit your post.

thanks i have changed that now

Formatting…

- alias: 'Turn on bed room lights'
  trigger:
    platform: event
    event_type: click
    event_data:
      entity_id: binary_sensor.switch_158d0001e822ab
      click_type: single
  action:
    service: light.turn_on
    entity_id: light.tv_light

Thank you very much sir, its working now.
I tried couple of hours in night but could not figure it out.
Is there any rules for indentation as I am using both atom and notepad++ but still same issues.
Regards

Basically:

  • always use spaces
  • indent sub-keys 2 spaces below their parent

The tough bit to get your head around is the second one, but you’ll get there eventually, here is an annotated copy of your automation that hopefully will help you visualise it…

- alias: 'Turn on bed room lights'    # sub-key of automation
  trigger:   # sub-key of automation
    platform: event   #sub-key of trigger 
    event_type: click    #sub-key of trigger
    event_data:    #sub-key of trigger
      entity_id: binary_sensor.switch_158d0001e822ab    #sub-key of event-data
      click_type: single     #sub-key of event-data
  action:  #sub-key of automation
    service: light.turn_on    #sub-key of action 
    entity_id: light.tv_light    #sub-key of action 
1 Like

if you are using a xiaomi button, does it actually work? there was a breaking change in something like 0.82

event_type: xiaomi_aqara.click