Entity node - correct values

I have:

Then this:

Then this:

For the state it works, if motion then on, if not then off.
But now, every output is put also in BatteryLevel. currently e.g. it is 0 but if I change the sensor level to 80 it is 80 until motion is detected and then it’s 1 and then 0.

How can I get the output of in the picture above “82” behind battery level?

1 Like

Ok I am not familiar with that device. I think it’s a multisensor. You have 3 values ( motion, light level and battery) coming out of a 1 node? Or these 3 gray nodes spitting them separately? Can you post the full flow in json format. Also change the debug note to ‘complete message’, maybe topic is different so you can re-route the message by topic

Hi, thank you for responding.

the debug output is only from that top node, the “motion” part of an aeotec trisensor. The other 2 nodes output the values which is in the example above 26.6 degrees C and 90 lux (light level).
Thus yes, these 3 nodes split them and the battery and motion output comes out of the top node.

How can I “change the debug note to ‘complete message’”?

[{"id":"fbbc3e4f.64b688","type":"mios-in","z":"4cc3ec41.6d206c","name":"HalVoor:TriSensorMotion","server":"381f006.0ce75","item":"Test:TriSensorMotion","exact":false,"x":190,"y":80,"wires":[["7e64c60e.97e338","eb77f624.36ef9","d7e24097.a64be8"]]},{"id":"fdb91951.f2c85","type":"mios-in","z":"4cc3ec41.6d206c","name":"HalVoor:TriSensorLux","server":"381f006.0ce75","item":"Test:TriSensorLux","exact":false,"x":180,"y":200,"wires":[["b7c7311d.f5ddf","7e64c60e.97e338"]]},{"id":"b7c7311d.f5ddf","type":"ha-entity","z":"4cc3ec41.6d206c","name":"Trisensor Lux","server":"c6b350c5.b8b3c","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Trisensor Lux"},{"property":"device_class","value":"lx"},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":500,"y":200,"wires":[["7e64c60e.97e338"]]},{"id":"eb77f624.36ef9","type":"ha-entity","z":"4cc3ec41.6d206c","name":"Trisensor Motion","server":"c6b350c5.b8b3c","version":1,"debugenabled":false,"outputs":1,"entityType":"binary_sensor","config":[{"property":"name","value":"Trisensor Motion"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"payload","stateType":"msg","attributes":[{"property":"BatteryLevel","value":"payload","valueType":"msg"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":510,"y":80,"wires":[["7e64c60e.97e338"]]},{"id":"4c318161.ea805","type":"mios-in","z":"4cc3ec41.6d206c","name":"HalVoor:TriSensorTemp","server":"381f006.0ce75","item":"Test:TriSensorTemp","exact":false,"x":180,"y":140,"wires":[["26bc9af7.e4219e"]]},{"id":"26bc9af7.e4219e","type":"ha-entity","z":"4cc3ec41.6d206c","name":"Trisensor Temperature","server":"c6b350c5.b8b3c","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Trisensor Temperature"},{"property":"device_class","value":"temperature"},{"property":"icon","value":""},{"property":"unit_of_measurement","value":"°C"}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":520,"y":140,"wires":[["7e64c60e.97e338"]]},{"id":"d7e24097.a64be8","type":"debug","z":"4cc3ec41.6d206c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1000,"y":120,"wires":[]},{"id":"381f006.0ce75","type":"mios-server","z":"","name":"Edge-2","host":"192.168.20.100","port":"3480"},{"id":"c6b350c5.b8b3c","type":"server","z":"","name":"Home Assistant"}]

here it is.
image

then also post the entire output msg in text format.

the 1 output:
{“topic”:“Test:TriSensorMotion:Tripped”,“payload”:1,"_msgid":“d1d0b5f3.be4768”}

the 0 output:
{“topic”:“Test:TriSensorMotion:Tripped”,“payload”:0,"_msgid":“f47a2e12.668cc”}

the 82 (made 85 this time) output:
{“topic”:“Test:TriSensorMotion:BatteryLevel”,“payload”:85,"_msgid":“3054c1d2.2376ae”}

Edit: I am playing for half an hour now… with a change node trying to change something… literally trying, but nothing works… it is my inability to find out what a topic/payload is. Logically I would try to change the payload from the topic Test:TriSensorMotion:BatteryLevel to msg.temperature or something and then use that value in the entity node… I think I would then be able to inject hte value like this?

but I think I do not understand the concept of node red there… any advice I really would appreciate. Steap learning curve for me :slight_smile:

I can’t get my head around what to do with that change node… “what do I need to change”?

problem is battery level and motion is are not coming in the same message but arriving separately. you can use a join node to merge the messages but it will be difficult to merge them based on number of messages or timeout. Function node can do it I guess.
i think easiest solution will be to create 2 sensors. instead of one sensor + battery attribute. something like this:

[{"id":"7f931544.ee825c","type":"inject","z":"de9989cc.589d18","name":"","topic":"","payload":"{\"topic\":\"Test:TriSensorMotion:Tripped\",\"payload\":1,\"_msgid\":\"d1d0b5f3.be4768\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":100,"wires":[["ca47aafe.dba068"]]},{"id":"ba0ed18d.85f5f","type":"inject","z":"de9989cc.589d18","name":"","topic":"","payload":"{\"topic\":\"Test:TriSensorMotion:Tripped\",\"payload\":0,\"_msgid\":\"f47a2e12.668cc\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":140,"wires":[["ca47aafe.dba068"]]},{"id":"8bbdbe9c.b473a","type":"inject","z":"de9989cc.589d18","name":"","topic":"","payload":"{\"topic\":\"Test:TriSensorMotion:BatteryLevel\",\"payload\":85,\"_msgid\":\"3054c1d2.2376ae\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":180,"wires":[["ca47aafe.dba068"]]},{"id":"13cdfa56.26d446","type":"debug","z":"de9989cc.589d18","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.payload","targetType":"msg","x":500,"y":100,"wires":[]},{"id":"ca47aafe.dba068","type":"switch","z":"de9989cc.589d18","name":"","property":"payload.topic","propertyType":"msg","rules":[{"t":"eq","v":"Test:TriSensorMotion:Tripped","vt":"str"},{"t":"eq","v":"Test:TriSensorMotion:BatteryLevel","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":300,"y":140,"wires":[["13cdfa56.26d446"],["650a28c8.63ffb8"]]},{"id":"650a28c8.63ffb8","type":"debug","z":"de9989cc.589d18","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.payload","targetType":"msg","x":500,"y":180,"wires":[]}]

The thing is I want to pass the value of the battery to the entity in hass.

So the motion sensor with a battery level:

Question is thus how I can change this:
{“topic”:“Test:TriSensorMotion:BatteryLevel”,“payload”:85,"_msgid":“3054c1d2.2376ae”}

to have that payload (85) to be sent as a msg.temperature and add it as a value in the attribute key “BatteryLevel”:

What do I put in a change node?

you can use the change node like this
image
but when this message arrives to sensor node seperately, i am not sure if it will update the sensor attrbute.
put the change node after the switch node like this:

Sorry I meant to not use your switch node but just change that line in my previous post.

Very simple change where topic is “Test:TriSensorMotion:BatteryLevel” change msg.payload to msg.temperature?

yes but it will not work because your sensor needs to have msg.temp and msg.payload in the same message in order to publish sensor state correctly. so i tried the flow context and i think it works.
to be clear: you have 1 node, sending 3 messages with 2 different topics, right?
so use the the switch node the seperate the topics: motion and battery.
motion topic goes directly to sensor, so you have your on/off information there.
battery level is saved to flow context and sensor gets the batter level from there.

[{"id":"7f931544.ee825c","type":"inject","z":"de9989cc.589d18","name":"on","topic":"Test:TriSensorMotion:Tripped","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":100,"wires":[["ca47aafe.dba068"]]},{"id":"ba0ed18d.85f5f","type":"inject","z":"de9989cc.589d18","name":"off","topic":"Test:TriSensorMotion:Tripped","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":140,"wires":[["ca47aafe.dba068"]]},{"id":"8bbdbe9c.b473a","type":"inject","z":"de9989cc.589d18","name":"battery","topic":"Test:TriSensorMotion:BatteryLevel","payload":"82","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":260,"wires":[["ca47aafe.dba068"]]},{"id":"ca47aafe.dba068","type":"switch","z":"de9989cc.589d18","name":"switch by topic","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"Test:TriSensorMotion:Tripped","vt":"str"},{"t":"eq","v":"Test:TriSensorMotion:BatteryLevel","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":330,"y":140,"wires":[["8752073f.a88538"],["69d37f8e.18f99"]]},{"id":"69d37f8e.18f99","type":"change","z":"de9989cc.589d18","name":"save battery to flow variable","rules":[{"t":"move","p":"payload","pt":"msg","to":"temp","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":180,"wires":[[]]},{"id":"8752073f.a88538","type":"ha-entity","z":"de9989cc.589d18","name":"test sensor","server":"e447d17a.16a64","version":1,"debugenabled":false,"outputs":1,"entityType":"binary_sensor","config":[{"property":"name","value":""},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"payload","stateType":"msg","attributes":[{"property":"batery level","value":"temp","valueType":"flow"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":770,"y":120,"wires":[[]]},{"id":"e447d17a.16a64","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true}]

Hi, this indeed works! Thank you for your help!

I realize I am not even half of understanding node-red concepts…

A question about that flow.temp. I have renamed to flow.temperature, but how does this work? Let’s say I have 10 of these motion sensors an have them all wanting to update their own battery level. Do I need to make ten of these flow.temp1, flow.temp2 etc.?

you can find some more details on how flow and global context work. https://nodered.org/docs/user-guide/writing-functions#storing-data

In this case, yes you need to create multiple flow.tempX values to store each battery levels (are they temperature or battery levels?).
BUT, there are always more than one way to do things in node-red. when things get too complicated, a function node solves it. https://nodered.org/docs/user-guide/writing-functions#writing-a-function

I was looking into https://nodered.org/docs/user-guide/context but do not really get how to use the “Flow - visible to all nodes on the same flow (or tab in the editor)” setting to be active on my “flow” then, that way I can just copy a flow and rename the sensors?

yes, just rename them as temp1, temp2 etc.

I meant this:

Imagine the “grey node” names differ but the “rest is the same”, that way only the “flow” value is saved and used in thát flow. Correct? Thus I do NOT have to use the flow.temp1 etc but can only sue a flow.temperature PER flow (thus the same name per flow)?

EDIT: have been playing… it seems indeed that the “entity node” must have a “State must be defined.” meaning that if I flow another, e.g. msg.temp to it without the msg.payload it won’t change it. Having that flow.temp in the “buffer”? changes it upon changing the msg.payload. Thus, if the battery status is updated and there is no motion detection, it will NOT be displayed in the entitiy in homeassistant… correct?

And another question:
If I restart home assistant then the motion sensor is “on” by default. How can I keep the state original?

flow means tab. so whatever you store in a flow context will be available in that tab.
Other words, flow is not the collection of nodes connected with lines. because technically all msg components are available as long as they are in the same line.
you need flow context when you need to access data from another “line” let’s say.
so you need to create different flow variables to see different values in each entity. otherwise you will keep updating the same value for all entities.

other question: you can create an inject node to publish ‘off’ message once on connect. so when you restart home-assistant it will restart the node-red addon (if you installed it as an add-on)

Thank you, more clear!

I unchecked the box “resend state and attributes” and that seems to also leave the value “off” after home assistant restart. and yes I have the addon.

immagine

You need Node-Companion integration for the entity on homeassistant

By