Hi.
I’m starting to play with node-red and I’m trying to ‘detect’ when bridghtness is changed for specific light.
First, I can’t get “event: state” for this…I don’t know why, but isn’t trigged when I change btight, just when I turn on/off the light.
But using “trigger: state” works and it’s triggered when I just change the brightness value. The problem is that “Switch” node isn’t doing anything with this output from trigger node. Why? What am doing wrong?
I already debugged message and changed to correct object in switch node, but still not working.
In your state_change node make sure to UNCHECK:
Current state equal previous state
Otherwise you will not get an attribute change since the state stays on
.
As for the rest, can you please export your flow and share it please?
This makes it much easier to help you.
Tks, it worked now with “event: state” node! The switch still not working.
Here’s the flow:
[{"id":"25dbaffd.77cbd","type":"tab","label":"Debuga","disabled":false,"info":""},{"id":"5771958c.6b8b5c","type":"server-state-changed","z":"25dbaffd.77cbd","name":"","server":"2ba92c0c.9dae24","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.74467000600194f5eeee","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":570,"y":380,"wires":[["65ce99c1.364ab8"]]},{"id":"65ce99c1.364ab8","type":"debug","z":"25dbaffd.77cbd","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1090,"y":360,"wires":[]},{"id":"f9c5261.506c2d8","type":"api-call-service","z":"25dbaffd.77cbd","name":"","server":"2ba92c0c.9dae24","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.74467000600194f5eeee","data":"{\"brightness_pct\": 15}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":720,"y":720,"wires":[[]]},{"id":"ed465104.3a5df","type":"inject","z":"25dbaffd.77cbd","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":430,"y":720,"wires":[["f9c5261.506c2d8"]]},{"id":"5546db44.898af4","type":"inject","z":"25dbaffd.77cbd","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":430.0000915527344,"y":800.000186920166,"wires":[["b4e6af5a.82532"]]},{"id":"b4e6af5a.82532","type":"api-call-service","z":"25dbaffd.77cbd","name":"","server":"2ba92c0c.9dae24","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.74467000600194f5eeee","data":"{\"brightness_pct\": 100}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":718.0000839233398,"y":801.0001640319824,"wires":[[]]},{"id":"699e9413.348bbc","type":"trigger-state","z":"25dbaffd.77cbd","name":"","server":"2ba92c0c.9dae24","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"light.74467000600194f5eeee","entityidfiltertype":"exact","debugenabled":false,"constraints":[],"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":560,"y":500,"wires":[["d825ce8.8c6793","4bb56309.24841c"],[]]},{"id":"d825ce8.8c6793","type":"debug","z":"25dbaffd.77cbd","name":"D1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1060,"y":500,"wires":[]},{"id":"4bb56309.24841c","type":"switch","z":"25dbaffd.77cbd","name":"","property":"data.event.new_state.attibutes.brightness","propertyType":"msg","rules":[{"t":"lte","v":"50","vt":"num"},{"t":"gte","v":"200","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":930,"y":560,"wires":[["28c6239b.bce47c"],["4c4fb0e6.dc1fe"]]},{"id":"28c6239b.bce47c","type":"api-call-service","z":"25dbaffd.77cbd","name":"","server":"2ba92c0c.9dae24","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.74467000600194f5eeee","data":"{\"flash\":\"long\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1260,"y":560,"wires":[[]]},{"id":"4c4fb0e6.dc1fe","type":"api-call-service","z":"25dbaffd.77cbd","name":"","server":"2ba92c0c.9dae24","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.74467000600194f5eeee","data":"{\"brightness_pct\":100, \"effect\": \"random\", \"flash\": \"long\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1250,"y":620,"wires":[[]]},{"id":"2ba92c0c.9dae24","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
try this:
[{"id":"1ac8bf58.313d71","type":"server-state-changed","z":"70124295.5e68f4","name":"","server":"2fba4297.e4145e","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.desklamp","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":310,"y":240,"wires":[["8ff1cd93.e458b"]]},{"id":"8ff1cd93.e458b","type":"switch","z":"70124295.5e68f4","name":"","property":"data.new_state.attributes.brightness","propertyType":"msg","rules":[{"t":"lte","v":"50","vt":"num"},{"t":"gte","v":"200","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":530,"y":340,"wires":[["910626b0.9b22e8"],["554cfd35.a197a4"]]},{"id":"910626b0.9b22e8","type":"debug","z":"70124295.5e68f4","name":"small","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":730,"y":320,"wires":[]},{"id":"554cfd35.a197a4","type":"debug","z":"70124295.5e68f4","name":"big","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":730,"y":400,"wires":[]},{"id":"2fba4297.e4145e","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]
You should get two different messages in the debug log. This will show you that the switch node actually works. I think the problem might be with your service calls. i.e.: turn off service call cannot be coupled with a flash.
It worked! Tks!
That flash and turn on/off was just for testing…the debug messages worked fine, so the switch is working!