Hi smart people
I'm trying to integrate my Air Conditioner (Tuya based ) to Home Assistant (HA) and I've created this flow:
[{"id":"b2a1f22e.056c3","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"5ff38c3.6cecc74","type":"function","z":"b2a1f22e.056c3","name":"Turn on","func":"msg.payload ={\n dps : 2,\n set : msg.payload*10\n}\n\n/*\n\n */\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":780,"y":1120,"wires":[["4fd928d0.929f28","30c18e90.67a7f2"]]},{"id":"4fd928d0.929f28","type":"function","z":"b2a1f22e.056c3","name":"Air Conditioner","func":"msg.payload = msg.payload;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":960,"y":800,"wires":[["fb05d962.4cd2f8"]]},{"id":"fb05d962.4cd2f8","type":"change","z":"b2a1f22e.056c3","name":"","rules":[{"t":"move","p":"payload.data.dps","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1220,"y":1120,"wires":[["5946ffdb.db614"]]},{"id":"5946ffdb.db614","type":"split","z":"b2a1f22e.056c3","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":1410,"y":1120,"wires":[["6f02b39b.14856c"]]},{"id":"6f02b39b.14856c","type":"switch","z":"b2a1f22e.056c3","name":"","property":"parts.key","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"2","vt":"str"},{"t":"eq","v":"3","vt":"str"},{"t":"eq","v":"4","vt":"str"},{"t":"eq","v":"5","vt":"str"},{"t":"eq","v":"12","vt":"str"},{"t":"eq","v":"14","vt":"str"},{"t":"eq","v":"15","vt":"str"},{"t":"eq","v":"22","vt":"str"},{"t":"eq","v":"26","vt":"str"},{"t":"eq","v":"36","vt":"str"},{"t":"eq","v":"101","vt":"str"},{"t":"eq","v":"102","vt":"str"},{"t":"eq","v":"103","vt":"str"}],"checkall":"true","repair":false,"outputs":14,"x":1570,"y":1120,"wires":[[],["a14bcf2e.7de4d"],[],[],[],[],[],[],[],[],[],[],[],[]]},{"id":"a14bcf2e.7de4d","type":"switch","z":"b2a1f22e.056c3","name":"Below or above 16","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"160","vt":"str"},{"t":"lt","v":"160","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1490,"y":800,"wires":[["c9d7100f.72405"],["c129feeb.05799"]]},{"id":"c9d7100f.72405","type":"function","z":"b2a1f22e.056c3","name":"","func":"msg.payload = msg.payload / 10;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1680,"y":780,"wires":[["92094df5.9944"]]},{"id":"92094df5.9944","type":"api-call-service","z":"b2a1f22e.056c3","name":"AC Kontor Cooling Temp","server":"1dbb4297.18e25d","version":1,"debugenabled":false,"service_domain":"input_number","service":"set_value","entityId":"input_number.ac_office_cooling_temp","data":"{\"value\":\"{{payload}}\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1890,"y":760,"wires":[["2643b8fc.154dd8"]]},{"id":"2643b8fc.154dd8","type":"debug","z":"b2a1f22e.056c3","name":"Target temp","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":2110,"y":760,"wires":[]},{"id":"c129feeb.05799","type":"api-call-service","z":"b2a1f22e.056c3","name":"AC Kontor Cool Storage Temp","server":"1dbb4297.18e25d","version":1,"debugenabled":false,"service_domain":"input_number","service":"set_value","entityId":"input_number.ac_office_coolstorage_temp","data":"{\"value\":\"{{payload}}\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1810,"y":840,"wires":[["d763b660.3ba428"]]},{"id":"d763b660.3ba428","type":"debug","z":"b2a1f22e.056c3","name":"Target Cooling temp","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":2080,"y":840,"wires":[]},{"id":"e69a41e1.b96ab","type":"inject","z":"b2a1f22e.056c3","name":"Set cooling temp 16 degree (160)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"data\":{\"devId\":\"XXXXXXXXXXXXXX\",\"dps\":{\"2\":160}},\"deviceId\":\"XXXXXXXXX\",\"deviceName\":\"Airconditioner\"}","payloadType":"json","x":950,"y":660,"wires":[["fb05d962.4cd2f8"]]},{"id":"d64df7cf.91e318","type":"inject","z":"b2a1f22e.056c3","name":"Set cooling temp 20 degree (200)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"data\":{\"devId\":\"XXXXXXXXXXXXXX\",\"dps\":{\"2\":200}},\"deviceId\":\"XXXXXXXXX\",\"deviceName\":\"Airconditioner\"}","payloadType":"json","x":950,"y":700,"wires":[["fb05d962.4cd2f8"]]},{"id":"30c18e90.67a7f2","type":"debug","z":"b2a1f22e.056c3","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":950,"y":1120,"wires":[]},{"id":"13bf8f39.0dc3f1","type":"trigger-state","z":"b2a1f22e.056c3","name":"","server":"1dbb4297.18e25d","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"input_number.ac_office_cooling_temp","entityidfiltertype":"exact","debugenabled":false,"constraints":[],"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":510,"y":1120,"wires":[["5ff38c3.6cecc74"],[]]},{"id":"1dbb4297.18e25d","type":"server","name":"Home Assistant","legacy":false,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
I'm facing a problem with feedback loops I cannot get around. There are no issues when the actions are triggered from Home Assistant (HA) itself but becuase the AC can trigger value changes itself, either temperature changes or when you change values on the device, I will face a problem with feedback loops. I've just created a test function called Air Conditioner and two inject triggers for temperature change simulation from the AC and this is the part of the flow that will cause the problem.
The wanted behaviour of this flow:
- State change triggered from HA GUI: send to value to AC and do no more
- State change triggered from AC: send to HomeAssistant and do no more
What actually happens:
- State change triggered from HA GUI: sends to AC and send back to HA and thankfully stops because it's the same value as it already sent
- State change triggered from AC: sends to HA and sends back to AC because it's not same as the previous value (of course it could be). This is what I want to stop. Basically any change triggered from the AC should not be seen as a state change.
What is the smart solution here?
- To create a flow variable for each msg payload item representing either AC triggered or GUI triggered from HomeAssistant?
- Another possible solution could be to create separate set and get variables in HA?
Will be very thankful for any input to this challenge!