Get a value from a sensor with mqtt

Hallo all

First of all, thank you for all the help you give me.

i would like to use an "inject node" connected to an "mqtt out" to pull a "payload.illuminance_lux" value so it comes out of an "mqtt in node"
is it possible and how do you set it up?

[{"id":"8fac63a5a17dd303","type":"mqtt in","z":"fb88cea7421b6512","name":"","topic":"zigbee2mqtt/Sensor/illuminance_lux","qos":"2","datatype":"auto-detect","broker":"711011c119463c3b","nl":false,"rap":true,"rh":0,"inputs":0,"x":1020,"y":2260,"wires":[["93e8b16157eac356"]]},{"id":"dcb90c9a4f690539","type":"mqtt out","z":"fb88cea7421b6512","name":"","topic":"zigbee2mqtt/Sensor/illuminance_lux","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"711011c119463c3b","x":1230,"y":2200,"wires":[]},{"id":"93e8b16157eac356","type":"debug","z":"fb88cea7421b6512","name":"debug 14","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1300,"y":2260,"wires":[]},{"id":"333f5e04585b7f21","type":"inject","z":"fb88cea7421b6512","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":940,"y":2200,"wires":[["dcb90c9a4f690539"]]},{"id":"711011c119463c3b","type":"mqtt-broker","name":"MQTT Broker","broker":"192.168.1.106","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]

Your flow seems to work - it passes a message from inject to debug via an MQTT broker.

Is the problem that this flow does not work for you? In that case your MQTT broker is not working.

Or do you need help requesting data from the sensor?

I only get a timestamp out. 1690383855807. But I will like to get the payload.illuminance_lux value out.

so yes. I need to get date out from the sensor

That depends how your sensor works.

Some send data on a serial port, some by Mqtt over wi-fi.

Some send it at regular intervals, some you have to request the data.

So to advise further we will need to know the kind of sensor, how it is connected and possibly the type of firmware it runs.

I use a Philips Hue motion sensor

I don't use zigbee2MQTT but I would think that the sensor will send periodic updates, particularly when there is a change of state on the sensor.

If you watch the incoming messages with a debug node do you see this data ?

EDIT just checked docs, you cannot force this reading so will have to wait for it to be sent to you.

Illuminance_lux (numeric)

Measured illuminance in lux. Value can be found in the published state on the illuminance_lux property. It's not possible to read (/get) or write (/set) this value. The unit of this value is lx.

okay. to bad

I was trying to use it as a "events: state" node, but I have to use home assistant node then.

What are you trying to do with the information that you need to poll the device ?

When a state msg arrives via MQTT you can take appropriate actions based on the lux value.

If you want to take actions at a later time, then you could store the lux values into a context variable as they arrive, then use the last stored value in your flows.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.