Question about automation and zigbee

Hi Guys, I have some question about automation, here’s an example automation I create with UI help.

- id: '1575184069670'
  alias: Turn on light
  trigger:
    device_id: myswitch
    domain: switch
    entity_id: switch.shenzhen_neo_electronics_co_ltd_power_plug_12a_switch_3
    platform: device
    type: turned_on
  action:
    device_id: mylights
    domain: light
    entity_id: light.warehouse
    type: turn_on

My question is, what is device_id ? I tried to change it to whatever I like it seems ok, but when I delete it, an error occurred, but I looked everywhere on tutorial or examples, they dont need device_id, and domain in their automation, why do it cant work on mine ?

Second question about zigbee, I have an aqara double switch, but seems I can’t find a working example of how to automate it, i tried automation like this

- alias: Switch Hue Light
    trigger:
      platform: mqtt
      topic: 'zigbee2mqtt/0x00158d0002fcedf9_click'
    condition:
      condition: template
      value_template: '{{ "single" == trigger.payload_json.click }}'
    action:
      service: light.toggle
      entity_id: light.warehouse

But it won’t work, in zigbee2mqtt, my aqara switch shows as follows

zigbee2mqtt:info  2019-12-08T02:45:01: MQTT publish: topic 'zigbee2mqtt/0x00158d0002fcedf9', payload '{"battery":100,"voltage":3045,"linkquality":65,"click":"left"}'
zigbee2mqtt:info  2019-12-08T02:45:01: MQTT publish: topic 'zigbee2mqtt/0x00158d0002fcedf9', payload '{"battery":100,"voltage":3045,"linkquality":65,"click":""}'

PS: I’m using CC2531 USB Stick for zigbee

In your output the word is ‘left’ not ‘single’

No idea what the device id is, it’s probably an internal unique number that homeassistant identifies your devices with. My understanding is that if you create ‘device’ based automations you shouldn’t be editing them in code.

I think it was a bad design choice personally, would have much preferred that the UI presented the devices and the available options, but that when you hit save it converted it into a traditional automation.

So like in the ui you click ‘ceiling light is turned on’ but the output yaml is a state trigger, to on, for light.ceiling. Can’t see why we needed a whole new platform that’s less flexible, but there we are.

1 Like

Thanks for your reply.
So, I tried to make one simple automation like this

- alias: 'Turn on Bedside when Warehouse on'
  trigger:
    platform: state
    entity_id: light.warehouse
    to: on
  action:
    service: light.turn_on
    entity_id: light.side_bed

When my warehouse light is on, it will turn on my side bed lights too, but an error occurred.So, what went wrong this time ?


- alias: 'Turn on Bedside when Warehouse on'
  trigger:
    platform: state
    entity_id: light.warehouse
    to: on
  action:
  - data:
      entity_id: light.side_bed
    service: light.turn_on
 
    to: 'on'

Wow, thanks man, it actually work, so when to use the quote and when to not using it ? I’m still confused.

That’s a very good question. The short answer is always use 'on' and 'off' for state values. Without the quotes, on and off mean something else.

Thanks for the explanation, and thank you for your help.

And for the zigbee, finally I found a solution here, apparently the code above is when you have aqara hub, but when you use CC2531 USB, the code is different, like this

- id: Test2 WORKED!!
  alias: Turn on Dispenser
  trigger:
      platform: state
      entity_id: sensor.aqarabutton_click
      to: 'left'
  action:
      service: light.toggle
      entity_id: light.warehouse

You had originally marked my post as the Solution:

Screenshot from 2019-12-08 00-58-06

then you marked your own post as the Solution.

It’s the custom of this community to attribute ‘Solution’ to the post that contains the idea that resolves the issue. The issue was that you were using unquoted state values and the solution was to supply the missing quotes. That’s what my original post revealed.

Oh, I’m sorry, I thought I can make 2 answers as solution, haha.

I have marked yours again as solution.

1 Like