#How can I compare one entity to another

1 messages · Page 1 of 1 (latest)

frosty crypt
#

This is pretty messy but it works for me:
[{"id":"56efbd7d384efb7c","type":"debug","z":"de7b904327891368","name":"Match","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1050,"y":560,"wires":[]},{"id":"58e18ab5591404b8","type":"api-current-state","z":"de7b904327891368","name":"","server":"13c994bb.7a47db","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"switch.tall_lamp_plug","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":530,"y":600,"wires":[["b0856ede3eee4ba3"]]},{"id":"9d3ece9336a0abdc","type":"function","z":"de7b904327891368","name":"Rename to payload2","func":"msg.payload2 = msg.payload;\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":240,"y":600,"wires":[["58e18ab5591404b8"]]},{"id":"f67327f01a0b42be","type":"inject","z":"de7b904327891368","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"payload\":\"off\",\"data\":{\"entity_id\":\"switch.paper_lamp_plug\",\"old_state\":{\"entity_id\":\"switch.paper_lamp_plug\",\"state\":\"on\",\"attributes\":{\"friendly_name\":\"Paper lamp plug\"},\"last_changed\":\"2024-08-19T05:28:17.478062+00:00\",\"last_reported\":\"2024-08-19T05:28:17.478062+00:00\",\"last_updated\":\"2024-08-19T05:28:17.478062+00:00\",\"context\":{\"id\":\"01J5MHQ1R3FZFZ5RMPH0KY7R0B\",\"parent_id\":null,\"user_id\":\"b03ddafa36c745a79034b07f677f6d4b\"}},\"new_state\":{\"entity_id\":\"switch.paper_lamp_plug\",\"state\":\"off\",\"attributes\":{\"friendly_name\":\"Paper lamp plug\"},\"last_changed\":\"2024-08-19T05:28:32.757549+00:00\",\"last_reported\":\"2024-08-19T05:28:32.757549+00:00\",\"last_updated\":\"2024-08-19T05:28:32.757549+00:00\",\"context\":{\"id\":\"01J5MHQGND3HNN02XRZJP4YPS6\",\"parent_id\":null,\"user_id\":\"b03ddafa36c745a79034b07f677f6d4b\"},\"timeSinceChangedMs\":8}},\"topic\":\"switch.paper_lamp_plug\",\"_msgid\":\"09eb6c2d73150fd4\"}","payloadType":"json","x":70,"y":600,"wires":[["9d3ece9336a0abdc"]]},{"id":"b0856ede3eee4ba3","type":"switch","z":"de7b904327891368","name":"Compare payload to payload2","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"payload2.payload","vt":"msg"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":830,"y":600,"wires":[["56efbd7d384efb7c"],["583b543f2d678a51"]]},{"id":"583b543f2d678a51","type":"debug","z":"de7b904327891368","name":"No match","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1060,"y":640,"wires":[]},{"id":"13c994bb.7a47db","type":"server","name":"Home Assistant","addon":true}]

#

I'm using the function msg.payload2 = msg.payload; return msg;
in order to store both payloads in the message, and then using the switch to compare them

#

Obviously you can change which values you're storing through the function and comparing in the switch, I just used the payload as it gave me easy access to on/off for my switches

#

You also have the option of a template sensor in HA that is true when values match