Node-red state-changed question

Hi All

I have 2 questions, maybe somebody can help.
I want to log all events to a file. The logging is working perfectly, but I have an input button to swich on/off this logging.

  1. When I swich on the input_boolean.my_log button and using current state halt if OFF its not wokring for events “state changed” why ? the events is going through, not stoping.
  2. If I using function box, is there any posibility to get the state of an Entity ? for example get the state of “input_boolean.my_log” entity ?

Thx

I’m doing the same with several boolean and it works fine … can you share your flow and maybe a debug output?

The current state, does not work properly if it receives from input an entity_id in data. This is one annoying thing about the ha node that apparently is fixed in a fork.

Paste your flow here so we can figure out how to fix it.

AFAIK there is no way of getting the state of a sensor from ha in a function node. But you can use context flow or global to define variables or objects, which can be called in a function. You need a flow that pushes those variables into a global or flow context.

Thx four your answer !

Here is the flow:
[{“id”:“43da2905.ce43f8”,“type”:“server-events”,“z”:“445dee22.e6fcf”,“name”:“All_Evt”,“server”:“b5b17e21.382d5”,“x”:210,“y”:160,“wires”:[[“73e5a4b2.aaae2c”]]},{“id”:“73e5a4b2.aaae2c”,“type”:“api-current-state”,“z”:“445dee22.e6fcf”,“name”:“is On ?”,“server”:“b5b17e21.382d5”,“halt_if”:"",“override_topic”:true,“override_payload”:true,“entity_id”:“input_boolean.my_log”,“x”:380,“y”:160,“wires”:[[“bb43681e.31a408”]]},{“id”:“bb43681e.31a408”,“type”:“debug”,“z”:“445dee22.e6fcf”,“name”:"",“active”:true,“tosidebar”:true,“console”:false,“tostatus”:false,“complete”:“true”,“x”:590,“y”:160,“wires”:[]},{“id”:“b5b17e21.382d5”,“type”:“server”,“z”:"",“name”:“Home Assistant”,“url”:“https://xxx.duckdns.org”,“pass”:“xxx”}]

here is he log: even if the input_boolean.my_log is OFF I get the debug msg.

{“event_type”:“state_changed”,“topic”:“sun.sun”,“payload”:“above_horizon”,"_msgid":“3956c37.fa7d43c”,“data”:{“entity_id”:“sun.sun”,“state”:“above_horizon”,“attributes”:{“next_dawn”:“2018-09-05T03:35:31+00:00”,“next_dusk”:“2018-09-04T17:51:17+00:00”,“next_midnight”:“2018-09-04T22:42:14+00:00”,“next_noon”:“2018-09-05T10:42:22+00:00”,“next_rising”:“2018-09-05T04:07:02+00:00”,“next_setting”:“2018-09-04T17:19:42+00:00”,“elevation”:5.09,“azimuth”:274.63,“friendly_name”:“Sun”},“last_changed”:“2018-09-04T04:05:43.352660+00:00”,“last_updated”:“2018-09-04T16:42:30.346128+00:00”,“context”:{“id”:“df8c71ebea2f47d9a8bbcb6366b58a53”,“user_id”:null}}}

This is what I do in meanwhile. The below code is taking reading the different states of my “input_select” and putting it into a global Node-Red variable. Additionally any change event on the “input_select” is updating the global variable. This works as well with input_boolean and others.

[{"id":"b0ffd969.333678","type":"inject","z":"35719aac.81cfb6","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":"15","x":128,"y":413,"wires":[["eea63462.cddd18","c5335a60.46c848","6339996f.da7318","57960fa1.d9ee1","534c71d3.7cae2","da75942e.1e1528","8a8b58d7.fee718","a54c71dd.bf08a","3bffa244.fceeae"]]},{"id":"c5335a60.46c848","type":"api-current-state","z":"35719aac.81cfb6","name":"light_timer","server":"4f769a6d.58f8c4","halt_if":"","override_topic":true,"override_payload":true,"entity_id":"input_select.light_timer","x":328,"y":393,"wires":[["efae7e51.c4d46"]]},{"id":"8d1bb00e.3c27f","type":"trigger-state","z":"35719aac.81cfb6","name":"light_timer","server":"4f769a6d.58f8c4","entityid":"input_select.light_timer","debugenabled":false,"constraints":[],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"x":328,"y":353,"wires":[["efae7e51.c4d46"],[]]},{"id":"efae7e51.c4d46","type":"change","z":"35719aac.81cfb6","name":"Light_timer","rules":[{"t":"set","p":"Light_timer","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":568,"y":373,"wires":[["ebb82fda.772aa"]]},{"id":"ebb82fda.772aa","type":"debug","z":"35719aac.81cfb6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":898,"y":413,"wires":[]},{"id":"4f769a6d.58f8c4","type":"server","z":"","name":"Home Assistant","url":"http://hassio.local:8123","pass":"xxxx"}]

Yeah, that’s not going to work. That node receives all events, as objects flow they come with entity_id’s that override the current state node, which is the annoyance i mentioned before.

Use a switch node after all events that to filter the entity_id or use the state_changed node an specify the entity there. This will only generate objects if state change.

Thnak you for your answers.

Sortly means 1 and 2 is not working at the momment. These are workaround.
Is there a poibility to update the hassio node-red with these features ?

What features ?