Node-RED zigbee device status question

I have a question about how to make sure a zigbee device is alive before sending it a command.

Basically I have Sengled bulbs that are on Lutron dimmers. My lighting logic turns on the lights at a specified time and sends JSON states to the bulbs. My issue is that the command for the bulbs is sent at the same time that the Lutron switch is turned on, so the bulbs have not come online yet to recieve the command.

I am thinking that the last seen value is probably the easiest way to wait for the device to connect.

Does someone already have an example where they are doing this?

if would be nice if core had a simple device node that could be used for determining if a device is alive or not based on a user settable timeframe as part of the Z2m nodes.

1 Like

First mention … it’s not good for a mesh or for smart bulbs to consistently kill power or change power level to them. Although yours do not repeat, there can be a ton of issues with doing things this way. Including dead bulbs. But, it’s your choice. I’m simply making a statement. (If this is what you’re actually doing?)

Second: You can just use a zigbee get node or trigger your changes based on status. Hook a debug node to a zigbee in node and run your flow to see what status will put out for you and if you can act on it. Use complete output to get the full picture.

Third:

These features are on the roadmap or may already exist with SYS|API. I’m working with Markus to get this documented. More to come.

I was kind of on the fence about just leaving the lutron dimmers on all the time, so we will see just how hardy these bulbs are over time. I like having the outdoor lights still work even if the bulbs were to get swapped with just dumb bulbs

This is what I am doing, however, most of the information is from the last time the device checked in so its useless for current status. The only thing that seems usable is the “last seen”. I was hoping someone already had a flow for comparing the last seen time stamp to the current time and seeing if its within a definable time window…

image

I have my outside lights on a smart switch with Sengled colors in them, but I leave them on all the time. The reason I left it smart was so that if someone turns the switch off, then it’ll turn right back on. I can tell you that you’ll kill those sengled almost straight away. I managed to kill ones doing that inadvertently. My recommendation is to leave them powered and just make it easy on yourself to control the bulbs directly and have the switches there to make sure they don’t lose power.
I personally don’t think that you will be able to reliably achieve what you want in that manner. They’re just not meant to turn be turned off like that.

I think I remember reading about the same in the Node-Red forum. Did you check there by chance? Or in their Reddit? It sounds familiar, but I don’t think it was discussed here.

You could also use a delay node, after the power on command and before the state settings, set to x seconds. I’m not using sengleds or that style of dimmer, but in general it will take a pretty constant amount of time from power up to online.

@april.brandt knock on wood, I have been powering them off and on everyday since September! I am probably on borrowed time, so hopefully they dont all start failing on me.

Unless there is just no other way, I really dont like to base anything on just timing. I think I found a couple ways that may work, but we’ll see.

One question I have is that Core seems to be calculating the time since last check in already. But I’m not clear how often this updates, or who is pushing the update if the device is offline. The time shown below the Core node doesnt appear to be someting included in the payload.

image

I dont see a way to view that time in the payload or the little red box status?

1 Like

Probably best that @markus responds to this one.

While you definitely would be much better off NOT powering off smart bulbs, here’s a way of doing what you want using triggers and not timing:


This flow doesn’t use proper payloads for the devices and is just a conceptual one, but it should explain how to do it with the actual devices.
When ON is sent it goes to the Lutron switch and also straight to the Sengled bulb, if the bulb didn’t have power when the first message was sent it will get it again once it reports in (ie any message at all is received from the bulb). It does this by having the new state saved as a global and a throttle node is set to let ONE message through from the bulb and then send whatever was saved to the global to the bulb.

[{"id":"1b78bed3208bf327","type":"zigbee2mqtt-in","z":"1ae1a884.3eb117","name":"","server":"c292ab1e.8d2318","friendly_name":"Study - Alice Desk Lamp (ZNLDP12LM)","device_id":"0x00158d000450dd60","state":"0","outputAtStartup":true,"filterChanges":false,"enableMultiple":false,"x":190,"y":2580,"wires":[["8d0a90933e056a12","83f0be91817af4d1"]]},{"id":"8d0a90933e056a12","type":"debug","z":"1ae1a884.3eb117","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":450,"y":2600,"wires":[]},{"id":"3605fcee94d09fde","type":"inject","z":"1ae1a884.3eb117","name":"Inject ON","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":120,"y":2400,"wires":[["0429579cd0f68002","0b6de634fdeda33a"]]},{"id":"db1b4392cbba6194","type":"debug","z":"1ae1a884.3eb117","name":"On to Lutron","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":550,"y":2380,"wires":[]},{"id":"0b6de634fdeda33a","type":"change","z":"1ae1a884.3eb117","name":"Save ON/OFF state to global","rules":[{"t":"set","p":"sengled_bulb_state","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":2480,"wires":[["6a697a06fa7d0f3e","ab7dcffcc28ee4d4"]]},{"id":"0429579cd0f68002","type":"switch","z":"1ae1a884.3eb117","name":"Only ON","property":"payload","propertyType":"msg","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":360,"y":2380,"wires":[["db1b4392cbba6194"]]},{"id":"ab5f95bb20270bda","type":"inject","z":"1ae1a884.3eb117","name":"Inject OFF","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":120,"y":2440,"wires":[["0429579cd0f68002","0b6de634fdeda33a"]]},{"id":"6a697a06fa7d0f3e","type":"debug","z":"1ae1a884.3eb117","name":"On to Sengled Bulb","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":950,"y":2480,"wires":[]},{"id":"83f0be91817af4d1","type":"throttle","z":"1ae1a884.3eb117","name":"","throttleType":"reset","timeLimit":0,"timeLimitType":"seconds","countLimit":0,"blockSize":0,"locked":true,"x":450,"y":2540,"wires":[["29b9c5f813116d84"]]},{"id":"29b9c5f813116d84","type":"change","z":"1ae1a884.3eb117","name":"Retrieve ON/OFF state from global","rules":[{"t":"set","p":"payload","pt":"msg","to":"sengled_bulb_state","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":2540,"wires":[["6a697a06fa7d0f3e"]]},{"id":"ab7dcffcc28ee4d4","type":"change","z":"1ae1a884.3eb117","name":"Reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":230,"y":2540,"wires":[["83f0be91817af4d1"]]},{"id":"c292ab1e.8d2318","type":"zigbee2mqtt-server","name":"COREZ2M","host":"10.10.2.1","mqtt_port":"1883","mqtt_username":"","mqtt_password":"","mqtt_qos":"0","tls":"","usetls":false,"base_topic":"zigbee2mqtt"}]

EDIT: connecting it like this may be better, but I doubt there’d be any issues with either:

2 Likes

April out of curiosity, did you go through a warranty claim with Sengled?

I searched their site a bit and these bulbs suprisingly have a three year warranty, and do say they can be controlled with a dumb switch and do not make any mention in the warranty about manually turning them off degrading life. They do say indoor only though :shushing_face:

1 Like

Ohhh … NO.
Snap!
Just threw them out.
I do use them outside in covered fixtures.
:roll_eyes:

Mine are outside and covered as well. They also state they are good down to -4 F, unfortunataly we will see how well they function below that threshold in a couple months :cold_face:

1 Like

Hey @parish99, @markus helped me make this function that compares the last seen to the current date and time. I use a switch to determine if it is longer than 24 hours and then sends an alert. It works well for selecting multiple Zigbee devices.

[{"id":"e6930bd0b54581b4","type":"zigbee2mqtt-get","z":"dc6673e15b3c95bd","g":"894e3e0f80ece7a8","name":"","server":"a73dca039ddcf006","friendly_name":"19 selected","device_id":["0x286d970001004fe4","0x286d9700010c63e0","0x286d9700010cba51","0x286d97000105f0ee","0x286d97000107f342","0x286d9700010cfe2c","0x286d97000107b031","0x286d9700010cfde6","0x286d9700010c1928","0x286d9700010c0f0b","0x286d97000107fc2c","0x286d970001003bd0","0x286d97000109e55e","0x286d9700010c549f","0x286d9700010ad0c9","0x286d9700010b2072","0xb0ce1814000e6639","0x286d9700010cb9e7","0x286d97000109c6c0"],"state":"0","enableMultiple":true,"x":270,"y":680,"wires":[["e897956088320f59"]]},{"id":"e897956088320f59","type":"split","z":"dc6673e15b3c95bd","g":"894e3e0f80ece7a8","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":410,"y":680,"wires":[["af4fa7cbe964ecd4"]]},{"id":"af4fa7cbe964ecd4","type":"function","z":"dc6673e15b3c95bd","g":"894e3e0f80ece7a8","name":"Convert Data and TIme","func":"msg.topic = msg.payload.topic;\nlet LastCon = msg.payload.payload.last_seen;\nmsg.payload.clean_last_seen = (new Date(LastCon)).toString();\nlet SrvCon = ((Date.now() - LastCon) / 1000) / 60; // Number of minutes\nmsg.payload.minutes = SrvCon;\nmsg.payload.minutes = parseInt(msg.payload.minutes.toFixed(1))\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":170,"y":760,"wires":[["3b4a66ee40ce34b8"]]},{"id":"3b4a66ee40ce34b8","type":"switch","z":"dc6673e15b3c95bd","g":"894e3e0f80ece7a8","name":"","property":"payload.minutes","propertyType":"msg","rules":[{"t":"lt","v":"20","vt":"num"},{"t":"gt","v":"1440","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":370,"y":760,"wires":[["703af6b8c64e765c"],["ef1edffda53f3aed"]]},{"id":"a73dca039ddcf006","type":"zigbee2mqtt-server","name":"CoreZ2M","host":"10.10.2.1","mqtt_port":"1883","mqtt_username":"","mqtt_password":"","mqtt_qos":"0","tls":"44fba63b5df6a436","usetls":false,"base_topic":"zigbee2mqtt"},{"id":"44fba63b5df6a436","type":"tls-config","name":"Defualt TLS","cert":"","key":"","ca":"","certname":"","keyname":"","caname":"","servername":"hooks1.oh-lalabs.com","verifyservercert":true,"alpnprotocol":""}]
1 Like

Yes WE will.
:grin:

How do you select multiple devices? It showed 19 devices when I imported but I couldnt figure out how you had multiple selected?

I just click the check box in the node-red-contrib-zigbee2mqtt node. This gives you the ability to select multiple devices at once. I’m on version 2.6.3 for those nodes.

Are you using NR3?

I dont have that check box option.

image

I am now, but I wasn’t when I started using this. Go to “Manage Pallet” and then search for Zigbee. You should see your node, and it should have an update button. You are probably on an older version.

I already updated it, but here is a screenshot of another node that needs an update.

Yep, that was it :point_up_2:

1 Like