Yes - I realized that and deleted. Probelem solved
I have tested a bit…and could not get it working that way as if I included reset into the Event:State message it just deleted it.
But when I did like this it looks to work (with a test sensor I can control):
The first Event:State node sends the event state (and some other info) into the delay node
The second Event:State node sends msg.reset (set to “reset”, but could be anyting)
Then reset node holds the message with the entity state and on every consecutive state that comes it also comes a reset deleting the former one…(?)
Need to test a bit more, but looks promising
Edit/Add:
It works!
Now I have also managed to pass working information to Notification and Email nodes!
Next step is to figure out how much of the code I need to duplicate to supervise several sensors!
So fun to learn.
Thanks for helping!!!
That’s correct - timeSinceChangedMs is the last time the database recorded data from the sensor. So, if the database has not recorded data from the sensor for x milliseconds… we have not heard from that sensor for x milliseconds
It’s not suppose to send that message. node: debug 2 is showing the output for when the If State condition is FALSE (we have data from the sensor that is less than x milliseconds). It’s working as intended.
Aha! I think I understand! I have to try to setup this again and play around a bit more.
Trying the other way now with two Event:State, the first sending the value, the other sending reset and that looks to work. Playing around with notifications and email now and I think I start to get hold of how to format with change nod to put together strings from multiple inputs and free text
Now I’m thinking about what will happen if I try to monitor multiple sensors (I want to check at least for (fridges and freezers) but maybe also my light sensor (rebuilt thermomerter/humidity sendor where humidity port is used for light) and maybe also an outdoor temp/hum and a few indor temp/hum…
Edit: With Event:State strategy I might need to duplicate everything (2xEvent:State+Delay) except the notificaiton part (change+notify+change+email) for every sensor…
This is definitely beyond my previously knowledge - but it’s great fun to learn! And what would
I have done without fourm…googling/reading helps a bit, but when not understanding this forum is brilliant
It works!!! And I think I understand why!
Now I have to try to build with this strategy as well!
Have to figure out where to input sensor ID and last read value and then pass it to notificaiton and email.
Will never learn without struggling!
Thanks!
Edit/Add: If I can figure out how to add my needed outputs (used msg.sensor_id and msg.sensor_value as self defined outputs to avoid mixing them with defaults and be sure to understand where debug info comes from) somewhare/in any way - then I might only need one PollState block for each sensor I want to check and I can poll inly few times a day, like every 12h and the process will very low intense (might not matter…to read a sensor is probably not that intense for a computer…but still… )
Add2: msg.payload and msg.topic is in the PollState output! Then I just have to format it and send to my Notifier and Email nodes!
Thanks again!
A better long-term solution is to get better sensors that work with Home Assistant integrations that have an Integration Quality Scale of Silver or better so that you can detect a state change when the entity goes “unavailable.” For example (I am not necessarily recommending Shelly though I do use it):
Ummm…I have looked at for example SHELLY-HT-WH that is supposed to live up to 18 mounth on a CR 123 battery and costs (only) about half of the 433MHz temp/hum sensors I (already) have.
The ones I have lives >4-5 year on 2xAA batteries, so they are very cheap in operation and have worked very well apart from that I have had to check now and then to see they still reports and that if two of them start to send simultaneously it can take a few hours before I get a reading again, but I can live with that.
I have 9 of them in operation…so I will prioritize to change 433MHz switches first. When budget allows, I might start swapping sensors as well.
But with the help I have got from you and WallyR in this forum it looks like I will be able to make the situation much more secure with my old sensors. Maybe not as good as with more modern ones, but probably well good enough!
Maybe this question starts to come OT, but it’s somewhat related…
I have thought about PollState node for another purpose.
I can see my phones battery percent as a sensor, but it is only updated when screen is unlocked.
I started trying to build a flow that switch of a plug for my charger when battery reach a set procentage (an input number helper)
As battery percent sensor is only updated when screen is unlocked, I tried the PollState node and that could fetch the value even if screen was locked.
But I don’t want node to poll that sensor 24/7, only while charging, but there is no input to the node.
You used the “If State” with the elegant expression:
entity().timeSinceChangedMs > 28800000
If I understand correct, it reads an entity in the database and if that is > X ms it returns true.
I tried to swap that entity for a toggle switch (just grabbed one for a lamp)
(Title should be Phone Charing, Entity ID should be battery percentage sensor and the entity of the plug feedign the charger in If State, ofcause)
and set = on…connected debug nodes to both outlets, but message payload comes from true independant of state of that lamp switch…
Is it possible to use PollState for what I want?
I did not test this but I think you want something like this:
[{"id":"8a8dc7dcc5eab749","type":"trigger-state","z":"8b43de8505f17be7","name":"Check Phone Battery > 85% & Switch","server":"","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"sensor.marks_pixel_battery_power","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":">","comparatorValueDatatype":"num","comparatorValue":"85"},{"targetType":"entity_id","targetValue":"switch.shelly_plug_1","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"ON"}],"inputs":0,"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","enableInput":false,"x":250,"y":700,"wires":[["5434357890c29262"],[]]},{"id":"5434357890c29262","type":"api-call-service","z":"8b43de8505f17be7","name":"","server":"","version":5,"debugenabled":false,"domain":"switch","service":"turn_off","areaId":[],"deviceId":[],"entityId":["switch.shelly_plug_1"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":580,"y":700,"wires":[[]]}]
There is also some good information in this guide and a cookbook for different things you might like to try:
https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/
Are you sure about that?
The Poll State node just pulls the state from HA.
If HA has no new information, then you just get the old one.
not really when you say so…it was a late night…
But what you say sounds logical when I think more about it
I need to do some more testing.
Maybe phone updates sensor when connected to main power/charging
But if so I still only want to poll that sensor when it’s charging.
I probably need to do some more testing and if it’s updating on charging some other node might work: Maybe the way MaxK suggested
You should have all the phone sensors if you have the Companion App on your phone. sensor.battery_level and sensor.battery_state should be in your Entities list (Settings → Devices & Services → Entities)
In general, you do not need to “poll” these sensors. HA / Node-Red will “see” when any of these sensor values change. You just need to detect the state change when it happens. The events: state, and trigger: state nodes will detect state changes and you can put your conditionals in there.
I always try to avoid polling when a state change can be detected.
But maybe the status is not being updated, because the Android settings for your HA companion app does not allow it. Maybe running in background is disabled or something like that.
OK - I have to try it out more in detail and see if I understand and can figure out how it works.
See when I get some more time to play around. Thanks for the lesion!!!
Have to check that when I get time to investigate what MaxK told me above! Thanks for input!
@MaxK and @WallyR - you both looks to just be waiting to help and teach me! THANKS for all quick replies!
I am always learning. Happy to help. Remember to help others learn too.
I will!..when I have learned enough… I do my best to help other in other forums for other topics where I have more knowledge and experience and hopefully that works in a circle in some way…
Hi, I maybe a bit old topic but i find it esier to use a trigger node to delay messages.
First send nothing and then I check the “extend delay if new message arrives”
and after the set time i send a specificed message to notify or whatever
You need to uncheck the “ignore if current state is equal previous state” in the state change node