I need to configure binary_sensor for MQTT inputs on my Shelly Pro 4PM. I succesfully manage to to with outputs (relays) - New Shelly Pro 4PM - wifi & LAN & MQTT - First of Shelly Pro Series - #9 by kslb.
Now, after some time I get data from MQTT Explorer what I get when I trigger input.
Payload ON:
rpc = {“src”:“shellypro4pm-XXXX”,“dst”:“shellypro4pm-XXXX-kabinet/events”,“method”:“NotifyEvent”,“params”:{“ts”:1637522890.20,“events”:[{“component”:“input:0”, “id”:0, “event”:“long_push”, “ts”:1637522890.20}]}}
Payload ON:
rpc = {“src”:“shellypro4pm-XXXX”,“dst”:“shellypro4pm-XXXX-kabinet/events”,“method”:“NotifyEvent”,“params”:{“ts”:1637522925.78,“events”:[{“component”:“input:0”, “id”:0, “event”:“single_push”, “ts”:1637522925.78}]}}
Payload OFF:
rpc = {“src”:“shellypro4pm-XXXX”,“dst”:“shellypro4pm-XXXX-kabinet/events”,“method”:“NotifyEvent”,“params”:{“ts”:1637522913.64,“events”:[{“component”:“input:0”, “id”:0, “event”:“btn_up”, “ts”:1637522913.64}]}}
We must consider, that we have 4 inputs, so we must know which input is triggered, so I tried with:
Not working:
- platform: mqtt
name: "Shelly Pro 4PM Input 1"
unique_id: "shellypro4pm-XXXX-kabinet-in1"
state_topic: "shellypro4pm-XXXX-kabinet/input/0"
payload_on: 1
payload_off: 0
qos: 0
Also not working:
- platform: mqtt
name: "Shelly Pro 4PM Input 1"
unique_id: "shellypro4pm-XXXX-kabinet-in1"
state_topic: 'shellypro4pm-XXXX-kabinet/input/0'
value_template: >-
{% if '"event":"btn_up"' in value %}
{{'OFF'}}
{% else %}
{{'ON'}}
{% endif %}
Last try:
- platform: mqtt
name: "Shelly Pro 4PM Input 1"
unique_id: "shellypro4pm-XXXX-kabinet-in1"
state_topic: 'shellypro4pm-XXXX-kabinet/events'
value_template: >-
{% if '"component":"input:0"' and '"event":"btn_up"' in value %}
{{'OFF'}}
{% elif '"component":"input:0"' and '"event":"single_push"' in value %}
{{'ON'}}
{% elif '"component":"input:0"' and '"event":"long_push"' in value %}
{{'ON'}}
{% endif %}
So, do anybody know how to achieve this?