Hardware: Processore Intel(R) Core™ i7-6700HQ CPU @ 2.60GHz, 2592
OS: Windows 10
Java Runtime Environment: Java™ SE Runtime Environment (build 1.8.0_211-b12)
openHAB version: 2.4.0-1
Hello everyone. I’m trying to capture a trigger event on a channel to turn on a light, but I have problems. I built a PIR sensor based on the ESP8266 chip. For each movement raised, send a message to a broker mqtt
You shoud get: {"uptime":0.02, "sensor"="pirOne", "state":"OFF", "motion":1}
When you have that as a payload, you can use a JSONPATH transformation in the MQTT thing to extract the state value:
Just add: transformationPattern="JSONPATH:$.state" to your channel definition
Type switch : mqttTrigger "MQTT_Trigger" [ stateTopic="sensor/door/pir", transformationPattern="JSONPATH:$.stat, trigger=true]
I removed the trigger option from the THINGS. A WARN now appears in the log file
2019-09-01 17:02:10.382 [WARN ] [eneric.internal.generic.ChannelState] - Command '{"uptime":"0.12","sensor":"pirOne","state":"OFF","motion":"1"}' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.{"uptime":"0.12","sensor":"pirOne","state":"OFF","motion":"1"}
But I still don’t see the expected message
What you see is the toString of the object I receive. This is the code loaded on the ESP8266:
OR
get you device to send several messages instead of one with several values.
This is what MQTT was designed for:
Topic: sensor/door/pir/uptime Payload:0.02
Topic: sensor/door/pir/state Payload OFF or ON
Topic: sensor/door/pir/motion Payload:1
Topic:sensor/door/pirsensorId Payload:pirOne
Then your MQTT thing in openhab should have the stateTopic as sensor/door/pir/state
No transformation required
That’s what would do. Use MQTT as designed and lighten the load for openHAB because the sensor did the work of separating the values. The ESP will have no trouble doing that
That’s good this is a valid JSON
Add the transformation as above in your channel definition to extract the $.state from the JSON
A switch channel only accepts ON or OFF as valid payloads
Make sure you intall the JSONPATH transformation in the PAPER UI
I add that the state actually never changes but always comes with the value OFF. For me the movement is detected by the arrival of the message on the queue.