How do I send the number of the scene triggered by my Popp keypad as payload with mqtt?

I have a Popp keypad, and when using code 1 it triggers scene one, code 2 triggers scene 2 and so on. I have this code working:

 alias: Popp-koder
  action:
    data:
      payload: 1
      topic: eg/Popp
    service: mqtt.publish
  condition: []
  id: '110223457'
  trigger:
    platform: event
    event_type: zwave.scene_activated
    event_data:
      entity_id: zwave.popp
      scene_id: 1

And the result in the receiving end (EventGhost) is like this:

15:16:12 MQTT.eg/Popp u"1"

But what I would like is something like this:

 alias: Popp-koder
  action:
    data_template:
      payload: '{{ trigger.payload }}'
      topic: eg/Popp
    service: mqtt.publish
  condition: []
  id: '110223457'
  trigger:
    platform: event
    event_type: zwave.scene_activated
    event_data:
      entity_id: zwave.popp

But it doesn’t work. It sends the MQTT, but with no payload.:

15:09:46 MQTT.eg/Popp u""

So how do I get it to send the scene that has triggered as the payload? It just seems so “messy” to create one for each code.

Your automation’s trigger is using the event platform. Therefore the automation’s action cannot refer to trigger.payload because it doesn’t exist.

When using the event platform as a trigger, here is what the Trigger State Object offers:

Template variable Data
trigger.platform Hardcoded: event.
trigger.event Event object that matched.
trigger.event.data Optional data

Therefore your automation’s action can refer to: trigger.event.data.scene_id

The automation would look something like this:

- id: '110223457'
  alias: Popp-koder
  trigger:
    platform: event
    event_type: zwave.scene_activated
    event_data:
      entity_id: zwave.popp
  condition: []
  action:
    service: mqtt.publish
    data_template:
      payload: '{{ trigger.event.data.scene_id }}'
      topic: eg/Popp
1 Like

You, sir, are the hero of the day! Thank you very much, that works like a charm! :+1:

Maybe you could help me out with one more thing: I want to unlock the door directly on one of the codes, but there has been changes in Z-Wave, so I have to use identity_id to make it work. But I can’t get it right. :frowning:

- alias: Døra - lüs
  action:
    data:
      entity_id:lock.id_lock_150
    service: lock.lock
  condition: []
  id: '1524476567232'
  trigger:
  - platform: mqtt
    topic: EG/Lock.Door

This gives me this error:

Invalid config for [automation]: expected dict for dictionary value @ data[‘action’][0][‘data’]. Got None. (See /home/homeassistant/.homeassistant/configuration.yaml, line 16). Please check the docs at Automation - Home Assistant
So I can’t understand how I get that entity id to work. The name of the lock is right.

This line appears to be lacking a space after the colon

      entity_id:lock.id_lock_150

It should be like this

      entity_id: lock.id_lock_150

And you’re right again! Thanks again! Only problem now is that they have changed from lock.unlock to lock.open, (nothing’s changed there, sorry) the lock.open service doesn’t work! :frowning: The GUI says “could not call service lock/open”, and nothing happens in the log. But I am guessing you don’t know why that can be. :slight_smile: I’ll open a new thread on that.

The working code was now lock.unlock. SO now I have it sending the scene number on MQTT and unlocking at once on code 1. Final question: Is it possible to make it react to boolean or? Like this:

- alias: Lüse opp dør med Popp kode 1
  action:
    data:
      entity_id: lock.id_lock_150
    service: lock.unlock
  condition: []
  id: '110234523457'
  trigger:
    platform: event
    event_type: zwave.scene_activated
    event_data:
      entity_id: zwave.popp
      scene_id: 1 or 2

it works on 1 if I only use that, or 2 if I only use that, but there’s obviously something wrong with the logic for “or”.

Use two triggers, one for each scene_id.

- alias: Lüse opp dør med Popp kode 1
  id: '110234523457'
  trigger:
    - platform: event
      event_type: zwave.scene_activated
      event_data:
        entity_id: zwave.popp
        scene_id: 1
    - platform: event
      event_type: zwave.scene_activated
      event_data:
        entity_id: zwave.popp
        scene_id: 2
  condition: []
  action:
    service: lock.unlock
    data:
      entity_id: lock.id_lock_150

I can tell you are using the Automation Editor to compose your automations. It sorts everything in alphabetical order thereby making the resulting automation needlessly difficult for humans to read.

Thanks! Actually I’m doing them in Geany. :wink: But my first automations were purely copied from the forum, so that’s probably why the stuff is in a weird sequence, with the action before the trigger.

Edit: Doing them in the editor doesn’t work because it eats my #### that I use between the automations to separate them, and it doesn’t always play nice with Norwegian special characters æøå.

Cool. I use Visual Studio Code.

If you have no further questions concerning this automation, you can do the community a service by marking my reply (containing the answer) with the Solution tag. Only you, the author this topic, can choose the reply that represents the answer to your question.

By marking it with the Solution tag, it will automatically place a check-mark next to the topic’s title. This indicates to other users that this topic has an accepted Solution. It will also place a link under your first post that leads to the solution. All this helps other users, who many have a similar question, find answers.

Solution marked, thanks for the tip! :slight_smile:

1 Like