Newbie needs help! How to test if two states are ON, then trigger event?

Hello! I have, I think, a fairly simple task. I'm a newbie at NR though, and I'm finding it incredibly difficult to wrap my head around.

Essentially I have a lawn mower and sprinklers, and they should never be on at the same time.
Lawn mower gets priority over the sprinklers.

If sprinklers are on and lawn mower starts mowing -> turn off sprinklers
If lawn mower is on and sprinklers start sprinkling -> turn off sprinklers

Should be very easy, right? The lawn mower doesn't have a simple on/off (more like "mowing" or "parked" etc), so I had to create a rather large switch that takes various text inputs and maps them to ON/OFF accordingly.

So now I should be able to somehow determine if they are both running at the same time.. but how? I'm lost when it comes to comparing two messages.

Current status (not working):

[{"id":"b6c312ca.754b2","type":"join","z":"dc46be20.8e86","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":430,"y":200,"wires":[["f04be0bc.9601"]]}]

Bonus points if you can help solve the error on the Mower State, "Node-RED custom integration needs to be installed in Home Assistant for this node to function correctly." (it IS installed, and it has updated variables before!)

EDIT: I've figured it out, see below. Please comment on how to do it better! :slight_smile:

I guess I get the bonus points - I added a 1 sec delay before the event node and now it works. :man_shrugging:

I believe I got the flows working, but as a newbie I'd love some criticism so I can learn if there are better ways to do it. I feel like this was very 'round about'.

[{"id":"dc46be20.8e86","type":"tab","label":"Sprinkler vs Mower!","disabled":false,"info":""},{"id":"896c9eb1.df30e","type":"switch","z":"dc46be20.8e86","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"Cutting","vt":"str"},{"t":"eq","v":"Cutting (manual timer override)","vt":"str"},{"t":"eq","v":"Going to charging station","vt":"str"},{"t":"eq","v":"Leaving charging station","vt":"str"},{"t":"eq","v":"Stopped but not on base","vt":"str"},{"t":"eq","v":"Paused","vt":"str"},{"t":"eq","v":"Charging","vt":"str"},{"t":"cont","v":"Parked","vt":"str"}],"checkall":"true","repair":false,"outputs":8,"x":90,"y":640,"wires":[["452d1da4.5a4194"],["452d1da4.5a4194"],["452d1da4.5a4194"],["452d1da4.5a4194"],["452d1da4.5a4194"],["452d1da4.5a4194"],["85d07afd.a07c38"],["85d07afd.a07c38"]]},{"id":"452d1da4.5a4194","type":"change","z":"dc46be20.8e86","name":"Set ON","rules":[{"t":"set","p":"payload","pt":"msg","to":"on","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"mower_status","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":240,"y":620,"wires":[["6ef232fa.16511c"]]},{"id":"85d07afd.a07c38","type":"change","z":"dc46be20.8e86","name":"Set OFF","rules":[{"t":"set","p":"payload","pt":"msg","to":"off","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"mower_status","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":240,"y":660,"wires":[["6ef232fa.16511c"]]},{"id":"cae42b7e.94a3d8","type":"server-state-changed","z":"dc46be20.8e86","name":"Mower ","server":"9344209b.b3b01","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"vacuum.robi","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":90,"y":740,"wires":[["896c9eb1.df30e"]]},{"id":"f04be0bc.9601","type":"api-call-service","z":"dc46be20.8e86","name":"Turn off Skydrop","server":"9344209b.b3b01","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"group.sprinklers","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":670,"y":100,"wires":[["3c2583ef.838bec"]]},{"id":"b6c312ca.754b2","type":"join","z":"dc46be20.8e86","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":430,"y":200,"wires":[["5e2ef6a4.af3698"]]},{"id":"63e91f91.c9932","type":"server-state-changed","z":"dc46be20.8e86","name":"Sprinkler Group","server":"9344209b.b3b01","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"group.sprinklers","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":100,"y":200,"wires":[["523d0a6d.856be4"]]},{"id":"c3447a2c.0fe768","type":"ha-entity","z":"dc46be20.8e86","name":"Mower Sensor","server":"9344209b.b3b01","version":1,"debugenabled":true,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"mower_state"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":100,"y":260,"wires":[["b6c312ca.754b2"]]},{"id":"523d0a6d.856be4","type":"switch","z":"dc46be20.8e86","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":260,"y":200,"wires":[["846771eb.3dc41"],[]]},{"id":"6f198be7.1e7c74","type":"debug","z":"dc46be20.8e86","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":710,"y":400,"wires":[]},{"id":"84e30133.8df8d","type":"inject","z":"dc46be20.8e86","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":170,"y":120,"wires":[["523d0a6d.856be4"]]},{"id":"6ef232fa.16511c","type":"delay","z":"dc46be20.8e86","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":160,"y":420,"wires":[["c3447a2c.0fe768"]]},{"id":"846771eb.3dc41","type":"change","z":"dc46be20.8e86","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"sprinkler_status","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":140,"wires":[["b6c312ca.754b2"]]},{"id":"5e2ef6a4.af3698","type":"function","z":"dc46be20.8e86","name":"","func":"if (msg.payload.sprinkler_status === \"on\"  &&  msg.payload.mower_status === \"on\" ) {\n    msg.payload = \"on\";\n} else {\n    msg.payload = \"off\";\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":560,"y":200,"wires":[["1709426e.3dcfce","6f198be7.1e7c74"]]},{"id":"1709426e.3dcfce","type":"switch","z":"dc46be20.8e86","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":690,"y":200,"wires":[["f04be0bc.9601"],[]]},{"id":"3c2583ef.838bec","type":"api-call-service","z":"dc46be20.8e86","name":"logbook.log","server":"9344209b.b3b01","version":1,"debugenabled":false,"service_domain":"logbook","service":"log","entityId":"","data":"{\"name\": \"NODE RED Triggered\", \"MOWER vs SPRINKLERS!\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":870,"y":100,"wires":[[]]},{"id":"9344209b.b3b01","type":"server","z":"","name":"Home Assistant [Bromley]","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Maybe label your nodes so from a quick view you can see which path is for your mower and which is for your sprinkler.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.