Switch MQTT JSONPATH

Dear All,

i’m having an issue with Getting a switch to update from MQTT Topic. All the examples I tried are not using JSONPATH.

MQTT TOPIC and JSON:
icarus/sonoff2/stats {“Motion”:0,“Light”:1,“Minutes”:38,“Hours”:1,“Days”:0,“Reboots”:152,“Heap”:44896,“RSSI”:"-49"}
SWITCH:
Switch Sonoff2_Light01 “Hall Lights” {mqtt="<[Server01:icarus/sonoff2/stats:state:ON:1],<[Server01:icarus/sonoff2/stats:state:OFF:0]"}

I have tried various combinations of;

  1. JSONPATH($.Light)
  2. JSONPATH($.Light == 1)

Switch Sonoff2_Light01 “Hall Lights” {mqtt="<[Server01:icarus/sonoff2/stats:state:ON:JSONPATH($.Light)],<[Server01:icarus/sonoff2/stats:state:OFF:JSONPATH($.Light)]"}

Switch Sonoff2_Light01 “Hall Lights” {mqtt="<[Server01:icarus/sonoff2/stats:state:*:JSONPATH($.Light)]"}

Is this even possible?

Many Thanks

This is a case where you can’t do it all within the Item definition.

The problem is you cannot set a Switch suing 0 and 1 and need to use ON or OFF (all caps). Since you can’t use more than one transformation at a time (i.e. JSONPATH and MAP), you will need to use a proxy Item and a Rule to extract the Light parameter and map it to ON or OFF.

And beyond that, your Item definitions are wrong. Per the docs:

Item myItem {mqtt="<direction>[<broker>:<topic>:<type>:<transformer>:<regex_filter>], <direction>[<broker>:<topic>:<type>:<transformation>], ..."}

Given this, the :* makes no sense on an inbound MQTT config.

Thanks for confirming