Multiple "payload_on"

Hello, I have this config:

  • platform: mqtt
    name: “Alarm”
    state_topic: “rfsignal”
    command_topic: “rfsignal”
    payload_on: “14110972”
    optimistic: false
    qos: 0
    retain: true

base on rf component. But my rf broadcast can contain multiple ID´s. Can I add multiple “payload_on” numbers in a singl eline or some aliases?
Thanks.

Please anybody has answer to my question?

I use Python script called rpi-rf_receive-mqtt. This script catches signals from RF receiver on GPIO27 (Raspberry).
If I push a button on my RF device, it broadcasts multiple numebrs but randomly. This is why I need to add multiple numbers to payload_on.

This is what RF python script shows if I push the button:
2018-06-20 19:24:45 - [INFO] rpi-rf_receive-mqtt: 1152 [pulselength 120, protocol 3]
2018-06-20 19:24:45 - [INFO] rpi-rf_receive-mqtt: 1154 [pulselength 120, protocol 3]
2018-06-20 19:24:46 - [INFO] rpi-rf_receive-mqtt: 5 [pulselength 296, protocol 1]
2018-06-20 19:24:46 - [INFO] rpi-rf_receive-mqtt: 2 [pulselength 120, protocol 3]
2018-06-20 19:24:46 - [INFO] rpi-rf_receive-mqtt: 1792 [pulselength 120, protocol 3]
2018-06-20 19:24:46 - [INFO] rpi-rf_receive-mqtt: 1664 [pulselength 120, protocol 3]
2018-06-20 19:24:46 - [INFO] rpi-rf_receive-mqtt: 128 [pulselength 120, protocol 3]
2018-06-20 19:24:57 - [INFO] rpi-rf_receive-mqtt: 1024 [pulselength 120, protocol 3]
2018-06-20 19:24:57 - [INFO] rpi-rf_receive-mqtt: 1664 [pulselength 119, protocol 3]
2018-06-20 19:24:57 - [INFO] rpi-rf_receive-mqtt: 1920 [pulselength 119, protocol 3]
2018-06-20 19:24:57 - [INFO] rpi-rf_receive-mqtt: 963 [pulselength 117, protocol 3]
2018-06-20 19:24:57 - [INFO] rpi-rf_receive-mqtt: 1536 [pulselength 120, protocol 3]
2018-06-20 19:24:57 - [INFO] rpi-rf_receive-mqtt: 1154 [pulselength 120, protocol 3]
2018-06-20 19:24:57 - [INFO] rpi-rf_receive-mqtt: 896 [pulselength 120, protocol 3]
2018-06-20 19:24:57 - [INFO] rpi-rf_receive-mqtt: 1024 [pulselength 119, protocol 3]
2018-06-20 19:24:58 - [INFO] rpi-rf_receive-mqtt: 32 [pulselength 1419, protocol 4]
2018-06-20 19:24:58 - [INFO] rpi-rf_receive-mqtt: 1666 [pulselength 119, protocol 3]
2018-06-20 19:24:58 - [INFO] rpi-rf_receive-mqtt: 2 [pulselength 610, protocol 5]
2018-06-20 19:24:58 - [INFO] rpi-rf_receive-mqtt: 1792 [pulselength 120, protocol 3]
2018-06-20 19:24:58 - [INFO] rpi-rf_receive-mqtt: 1536 [pulselength 120, protocol 3]
2018-06-20 19:24:58 - [INFO] rpi-rf_receive-mqtt: 1792 [pulselength 120, protocol 3]
2018-06-20 19:24:58 - [INFO] rpi-rf_receive-mqtt: 1024 [pulselength 119, protocol 3]

as you can see there are multiple number codes. 1792 or 1024 repeats. This is why I need to set those repeated codes because they are present in the list every time I push the button. This will cause HA will notice button being pushed every time not only in those times it send single code defines i payload_on.

Anybody? I will give you a beer :smiley:

The way I would approach it is to create a payload template that accepts all the know values and returns the value in payload on. This is assuming that what you have is a component that accepts templates - it is not exactly clear from your extract.

Something like

value_template: {% if value == "1792" %}14110972{% endif %}

see

So I will add multiple lines (values)? like:

value_template: {% if value == "1792" %}14110972{% endif %}
value_template: {% if value == "1234" %}14110972{% endif %}
value_template: {% if value == "12345" %}14110972{% endif %}
value_template: {% if value == "123456" %}14110972{% endif %}

etc…?

Almost. There can only be one value_template: entry, so you will need to include all incoming values in that. My jinja isn’t very good, but I think this would work,

value_template: {% if value == "1792" or value=="1234" %}14110972{% endif %}

or you might use else statements. Some jinja experts around might be able to suggest something more elegant.

1 Like

Thenk you @gpbenton. Please any expert - which solution is better concerning to CPU load (or system stability?). Multiple “IF” or multiple “ELSE” ? Thanks.

I saw this approach today, when browsing through the forum, which reminded me of your puzzle

I found that the code change from my PIR was the last character only, I just stripped that.

value_template: '{{ value_json.RfReceived.Data[:-1] }}'

Hope that helps

1 Like

helped me, thank you, you saved me!