Turn on a switch if 'heat' is read from any 6 inputs

I am getting rid of my Tado and bought Aqara E1 TrVs

Currently I have 6 TRVs. and I need to turn on a Aqara T2 switch to fire the boiler.
(If this was Crestron Simpl Windows I would have it done by now! using an ‘or’ and some other bits)
If any of the payloads contains ’ climate.‘room_name’ : msg.payload : string[4]
“heat”’ from any one of the TRVs, to turn on the Aqara T2 switch, unless they are all low, then to turn on off the switch.

I have asked Gemini 5 times, looked through copious amounts of youtube etc.
I am close but no cigar!

1 Like

Is your post a question or a statement? I don’t use API myself, so I could not ask ‘it’ for an appropriately withering and succinct put-down about being 6th on the list to be asked.

You have not provided a copy of your available data (nor your flow) so this has to be guesswork (so really not that different to asking AI). In Node-RED we have JSONata readily available as a powerful tool for data processing. Yes, you can always use ‘or’, as a number of individual tests. However as your base data is probably an ‘array’ or list of payloads, then then inclusive operator in may be a better choice. You can find in in many languages (did you see what I did there - wonder if AI can do that?) and yes in is in JSONata.

I often work backwards from what I want as the end result. So starting with an array in msg.payload such as [“cool”, “cool”, “cool”, “heat”, “heat”, “cool”] the JSONata

"heat" in payload

will return true if there is at least one “heat”. An effective “if a or b or c or d or e = heat”, and the predicate will only return false if there is no “heat” in the array.

The next step is to get “the payloads” into an array. Many of the WebSocket nodes - Current state / Event: state / Trigger - will return an array of states/results when given an array of entities as the subject. Otherwise you may have to use the Join node to get an array of msg.payloads from disparate sources.

After that, a bit of JSONata will easily take an array of objects such as

msg.payload = 
[
  {"entity": "climate.this_room", "state": "heat"},
  {"entity": "climate.the_other_room", "state": "cool"}
]

so payload.state will extract the state value as an array.

Hence you can go directly to the Action node, when setting up the action type to be either ‘switch.on’ or ‘switch.off’ and use something like

"switch." & ("heat" in payload.state ? "on" : "off")

to form the action command string at the point of use.

Cigars all round.

This is how I have solved a similar problem using Node-RED:
I want the heating to switch on or off depending on four variables. As these variables do not change in synchronism, I first collect them in a Join node. Then the output of that node is processed in a Function node using the following Java script:


// This Function node assumes the incoming message is a result of a Join node
// that combined four messages with 'true'/'false' payloads.

// Get the four values from the incoming message.
// The keys will depend on the topics of the original messages.
// Adjust 'msg.payload.message1' and 'msg.payload.message2' etc. to match your
// actual message structure from the Join node.
const cold = msg.payload.cold;
const price = msg.payload.price;
const night = msg.payload.night;
const thermo = msg.payload.thermo;

// Apply the priority logic:
if (thermo === true && night === true && price === true) {
  // Heating is needed
  // and there is no power limitation (i.e. nighttime does not restrict power use)
  // and the price is low enough
  msg.payload = true; 
} else 
msg.payload = false;

// Check if it is getting too cold Then we turn heating on, regardless of restrictions above.
if (cold === true) {
  msg.payload = true;
}

// Return the modified message to the next node in the flow.
return msg;

The output will control the heater switch.

Evening, Appreciate the replies. Excuse my Dyslexia, my brain thinks faster than my fingers.

This is my Heating Flow page.

[{"id":"c2049d501f05e4b9","type":"switch","z":"c62060377c8ef461","name":"Check for 'heat'","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"heat","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":610,"y":140,"wires":[["c9d3f1a2b4e5c6a7"],["e59263a23b207b5a"]]},{"id":"e59263a23b207b5a","type":"debug","z":"c62060377c8ef461","name":"Output (No 'heat')","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":880,"y":180,"wires":[]},{"id":"f1a2e3b4d5c6b7a8","type":"server-state-changed","z":"c62060377c8ef461","name":"Living Room Radiator","server":"b9a48d8e.e88e9","version":6,"outputs":1,"exposeAsEntityConfig":"","entities":{"entity":["climate.living_rad"],"substring":[],"regex":[]},"outputInitially":false,"stateType":"str","ifState":"","ifStateType":"str","outputOnlyOnStateChange":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[],"x":300,"y":120,"wires":[[]]},{"id":"e9c8b7a6d5c4b3a2","type":"server-state-changed","z":"c62060377c8ef461","name":"Hallway Radiator","server":"b9a48d8e.e88e9","version":6,"outputs":1,"exposeAsEntityConfig":"","entities":{"entity":["climate.hall_rad"],"substring":[],"regex":[]},"outputInitially":false,"stateType":"str","ifState":"","ifStateType":"str","outputOnlyOnStateChange":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[],"x":300,"y":180,"wires":[[]]},{"id":"a1d2e3b4c5d6e7f8","type":"server-state-changed","z":"c62060377c8ef461","name":"Study Radiator","server":"b9a48d8e.e88e9","version":6,"outputs":1,"exposeAsEntityConfig":"","entities":{"entity":["climate.study_rad"],"substring":[],"regex":[]},"outputInitially":false,"stateType":"str","ifState":"","ifStateType":"str","outputOnlyOnStateChange":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[],"x":300,"y":240,"wires":[[]]},{"id":"c9d3f1a2b4e5c6a7","type":"api-call-service","z":"c62060377c8ef461","name":"Turn on Boiler Switch","server":"b9a48d8e.e88e9","version":7,"debugenabled":false,"action":"switch.turn_on","floorId":[],"areaId":[],"deviceId":[],"entityId":["switch.boiler_control_l1"],"labelId":[],"data":"{}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","blockInputOverrides":false,"domain":"switch","service":"turn_on","mergecontext":"","x":870,"y":140,"wires":[[]]},{"id":"c2b2e6a3d1f4d3c9","type":"join","z":"c62060377c8ef461","name":"Wait for all to report","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","useparts":true,"accumulate":false,"timeout":"5","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":600,"y":300,"wires":[["e9a8f4c3b2a1d5c4","fbf0a1f1f6f60350"]]},{"id":"e9a8f4c3b2a1d5c4","type":"switch","z":"c62060377c8ef461","name":"All 'off'?","property":"payload","propertyType":"msg","rules":[{"t":"jsonata_exp","v":"$[0].payload = 'off' and $[1].payload = 'off' and $[2].payload = 'off'","vt":"jsonata"}],"checkall":"true","repair":false,"outputs":1,"x":780,"y":300,"wires":[["d8c7b6a5f4e3d2c1","223da61e7ab2fab2"]]},{"id":"d8c7b6a5f4e3d2c1","type":"api-call-service","z":"c62060377c8ef461","name":"Turn off Boiler Switch","server":"b9a48d8e.e88e9","version":7,"debugenabled":false,"action":"switch.turn_off","floorId":[],"areaId":[],"deviceId":[],"entityId":["switch.boiler_control_l1"],"labelId":[],"data":"{}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","blockInputOverrides":false,"domain":"switch","service":"turn_off","mergecontext":"","x":980,"y":300,"wires":[[]]},{"id":"b2ba5ab01e14dd4d","type":"debug","z":"c62060377c8ef461","name":"debug 5","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":660,"y":220,"wires":[]},{"id":"141338fd020c2efb","type":"server-state-changed","z":"c62060377c8ef461","name":"Living ","server":"b9a48d8e.e88e9","version":6,"outputs":1,"exposeAsEntityConfig":"","entities":{"entity":["climate.living_rad"],"substring":[],"regex":[]},"outputInitially":false,"stateType":"str","ifState":"","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":270,"y":380,"wires":[["c2049d501f05e4b9","c2b2e6a3d1f4d3c9","b2ba5ab01e14dd4d","4207ce0815b21690"]]},{"id":"e0a124938b828838","type":"server-state-changed","z":"c62060377c8ef461","name":"Hall","server":"b9a48d8e.e88e9","version":6,"outputs":1,"exposeAsEntityConfig":"","entities":{"entity":["climate.hall_rad"],"substring":[],"regex":[]},"outputInitially":true,"stateType":"str","ifState":"","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":270,"y":500,"wires":[["c2049d501f05e4b9","c2b2e6a3d1f4d3c9","b2ba5ab01e14dd4d","cc5a7c56fa45b3e4"]]},{"id":"def1795688a8405c","type":"server-state-changed","z":"c62060377c8ef461","name":"Study","server":"b9a48d8e.e88e9","version":6,"outputs":1,"exposeAsEntityConfig":"","entities":{"entity":["climate.study_rad"],"substring":[],"regex":[]},"outputInitially":false,"stateType":"str","ifState":"","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":270,"y":620,"wires":[["c2049d501f05e4b9","c2b2e6a3d1f4d3c9","b2ba5ab01e14dd4d","7419b0209b5f0848"]]},{"id":"a24485d785b72963","type":"inject","z":"c62060377c8ef461","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":980,"y":400,"wires":[["d8c7b6a5f4e3d2c1"]]},{"id":"fbf0a1f1f6f60350","type":"debug","z":"c62060377c8ef461","name":"debug 6","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":600,"y":440,"wires":[]},{"id":"223da61e7ab2fab2","type":"debug","z":"c62060377c8ef461","name":"debug 7","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":810,"y":517,"wires":[]},{"id":"4207ce0815b21690","type":"debug","z":"c62060377c8ef461","name":"debug 8","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":534,"y":507,"wires":[]},{"id":"cc5a7c56fa45b3e4","type":"debug","z":"c62060377c8ef461","name":"debug 9","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":540,"y":560,"wires":[]},{"id":"7419b0209b5f0848","type":"debug","z":"c62060377c8ef461","name":"debug 10","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":540,"y":620,"wires":[]},{"id":"b9a48d8e.e88e9","type":"server","name":"Home Assistant","addon":true}]

So when an Aqara TRV is turned on or off, the outputs that get generated are ‘off’ and ‘heat’, that is what I have gleaned from the debug symbols.
I have 3 TRVs connected for trialling.
So what I am trying to create is…
If any of the inputs have ‘heat’ THEN turn the Boiler ON
ELSE
Boiler OFF

So in my testing i have got as far as I can turn the boiler on, but when they are all ‘off’ it DOES NOT turn the boiler off…
Debug6 outputs
05/09/2025, 00:04:51[node: debug 6]
climate.hall_rad : msg.payload : array[1]
[ “off” ]

But the All Off does not do anything.
Nothing comes out of debug7
I suspect gemini has got something wrong in the Json on the ‘all off?’ switch node.

A little help with the last part would be appreciated.

P.

When a thermostat is calling for heat, the attribute hvac_action is heating. You can create a template binary sensor to tell you if a thermostat is calling for heat.

Settings → devices and services → helper tab → bottom right create new helper. Choose template and then binary sensor. Choose a name and enter the following in the template section.

{{ states.climate
  | selectattr('attributes.hvac_action', 'eq', 'heating')
  | map(attribute='entity_id')
  | list
  | count >= 1
}}

This sensor will be on when any of the thermostats are calling for heat. It will only be off if they are all off.

Really appreciate this and definately looks simpler than my node red flow, but somehow I cannot get it to work!
I have modified ‘hvac_action’ to ‘hvac_mode’ and ‘heat’

{{ states.climate
  | selectattr('attributes.hvac_mode', 'eq', 'heat')
  | map(attribute='entity_id')
  | list
  | count >= 1
}}

I gleaned this from ‘Dev Tools’ States
hvac_modes:

  • “off”
  • heat
    min_temp: 5
    max_temp: 30
    target_temp_step: 0.5
    preset_modes:
  • none
  • manual
  • away
  • auto
    current_temperature: 15.6
    temperature: 22.5
    preset_mode: manual
    friendly_name: Living Rad
    supported_features: 401

No matter what I change, i cannot fathom out why it does not work.

Still Learning!!

TIA

Paul

You’re looking at the list of hvac_modes. Please post a screenshot from Developer Tools / States showing state and attributes, like this:

If you can show it for TRVs in both conditions (asking for and not asking for heat), that would be helpful.

If, like my A/C units, the entity state value is the current action, this will be either “off” or “heat”, therefore msg.payload = “heat” is the ‘call for heat’ you are looking for. The attributes just hold other settings and setting parameter lists.

Actually seeing your flow is important.
It currently works for turning on the boiler since any TRV that changes to “heat” (this is in the msg.payload as the state value) will turn on the boiler. The problem is that the boiler will never turn off unless you have all six device settings at the same time to compare and check that none have ‘heat’.

You have six devices. When any one device changes from off to heat, or heat to off, you will see a state change in Home Assistant. The problem is, when one TRV changes, you actually need the current values of all of the others at the same time. The Join node, in this case, will wait just 5 seconds then return the only values it has - which is likely to be just the one TRV that has just changed state, and not all six.

There are many ways to build this flow. As a starter, this is working for me in testing with a couple of A/C units. Please ignore the error flags on the nodes - I have edited everything to your sensor values hence it no longer works for me.

The flow starts with a trigger that fires for any ‘climate’ device state change. You can use regex here for simplicity, or you can add each TRV separately as a list if you like. When any one TRV changes state, the node will start the flow.

Then I use Current state nodes to find the current state of all the TRVs in series, and a Change node to add the found value of each (msg.payload contains either ‘off’ or ‘heat’) to a new message object ‘trv’ against the device name. At the end of the flow I have an object with all the current states in it.

A very simple JSONata expression "heat" in trv.* will test for “heat” in an array of all the values, returning true if so, or false otherwise, and a Switch node will direct the message to either the turn on action or the turn off action accordingly.

There are several ways to simplify all of this, but it should work once you have the correct entities.

Since the trigger may fire six times together at start up, I have added a rate limiting node just to stop the action being called too many times in succession.

[{"id":"c9d3f1a2b4e5c6a7","type":"api-call-service","z":"a0400ae67c93e585","name":"Turn on Boiler Switch","server":"","version":7,"debugenabled":false,"action":"switch.turn_on","floorId":[],"areaId":[],"deviceId":[],"entityId":["switch.boiler_control_l1"],"labelId":[],"data":"{}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","blockInputOverrides":false,"domain":"switch","service":"turn_on","mergecontext":"","x":980,"y":1120,"wires":[[]]},{"id":"d8c7b6a5f4e3d2c1","type":"api-call-service","z":"a0400ae67c93e585","name":"Turn off Boiler Switch","server":"","version":7,"debugenabled":false,"action":"switch.turn_off","floorId":[],"areaId":[],"deviceId":[],"entityId":["switch.boiler_control_l1"],"labelId":[],"data":"{}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","blockInputOverrides":false,"domain":"switch","service":"turn_off","mergecontext":"","x":980,"y":1180,"wires":[[]]},{"id":"ba2635d9eaa086be","type":"server-state-changed","z":"a0400ae67c93e585","name":"Any Change?","server":"","version":6,"outputs":1,"exposeAsEntityConfig":"","entities":{"entity":[],"substring":[],"regex":["climate"]},"outputInitially":true,"stateType":"str","ifState":"","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":true,"ignoreCurrentStateUnavailable":true,"outputProperties":[{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":150,"y":900,"wires":[["9dd5d852520b205b"]]},{"id":"b696db3430f83e59","type":"api-current-state","z":"a0400ae67c93e585","name":"","server":"","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"climate.hall_rad","state_type":"str","blockInputOverrides":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":390,"y":960,"wires":[["91d0bcdee67ce2bc"]]},{"id":"9dd5d852520b205b","type":"api-current-state","z":"a0400ae67c93e585","name":"","server":"","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"climate.living_rad","state_type":"str","blockInputOverrides":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":390,"y":900,"wires":[["370c17f70c446f39"]]},{"id":"370c17f70c446f39","type":"change","z":"a0400ae67c93e585","name":"","rules":[{"t":"set","p":"trv","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"trv.living","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":900,"wires":[["b696db3430f83e59"]]},{"id":"91d0bcdee67ce2bc","type":"change","z":"a0400ae67c93e585","name":"","rules":[{"t":"set","p":"trv.hall","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":960,"wires":[["b75f739af0589b64"]]},{"id":"552ff85f257b654f","type":"change","z":"a0400ae67c93e585","name":"Turn on or off","rules":[{"t":"set","p":"payload","pt":"msg","to":"\"heat\" in items.*","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":890,"y":1020,"wires":[["c6e257df76bfd31d"]]},{"id":"c6e257df76bfd31d","type":"delay","z":"a0400ae67c93e585","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"2","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"allowrate":false,"outputs":1,"x":540,"y":1140,"wires":[["84788ea4a250cf44"]]},{"id":"84788ea4a250cf44","type":"switch","z":"a0400ae67c93e585","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":750,"y":1140,"wires":[["c9d3f1a2b4e5c6a7","d8c7b6a5f4e3d2c1"]]},{"id":"b75f739af0589b64","type":"api-current-state","z":"a0400ae67c93e585","name":"","server":"","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"climate.study_rad","state_type":"str","blockInputOverrides":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":390,"y":1020,"wires":[["59adcb245be341b6"]]},{"id":"59adcb245be341b6","type":"change","z":"a0400ae67c93e585","name":"","rules":[{"t":"set","p":"trv.study","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":1020,"wires":[["552ff85f257b654f"]]},{"id":"5ee4886793bdd86c","type":"global-config","env":[],"modules":{"node-red-contrib-home-assistant-websocket":"0.77.2"}}]

Cigar?

Yet a “nicer” pattern is to use the GetEntities, instead of checking single entities. The GetEntities node has “Count” mode, returning number of entities matched by both: their names and states

BTW I found GetEntities node underestimated.

[{"id":"e619260f6fbd83a2","type":"subflow","name":"Start Event","info":"","category":"","in":[],"out":[{"x":480,"y":170,"wires":[{"id":"7f828b55b50ff0e0","port":0}]}],"env":[{"name":"Event type","type":"str","value":"any_start","ui":{"icon":"font-awesome/fa-play-circle-o","type":"select","opts":{"opts":[{"l":{"en-US":"NR start"},"v":"nr_start"},{"l":{"en-US":"HA start"},"v":"ha_start"},{"l":{"en-US":"Any"},"v":"any_start"}]}}}],"meta":{},"color":"#DDAA99"},{"id":"ed8d9f55.70a2d","type":"inject","z":"e619260f6fbd83a2","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":130,"wires":[["7f828b55b50ff0e0"]]},{"id":"b46e7e0a.fef1f","type":"switch","z":"e619260f6fbd83a2","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"running","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":390,"y":80,"wires":[["7f828b55b50ff0e0"]]},{"id":"b66320a5.f8586","type":"server-events","z":"e619260f6fbd83a2","name":"","server":"6cdd0bc8.b8e434","version":3,"exposeAsEntityConfig":"","eventType":"home_assistant_client","waitForRunning":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"$outputData(\"eventData\").event_type","valueType":"jsonata"},{"property":"event_type","propertyType":"msg","value":"$outputData(\"eventData\").event_type","valueType":"jsonata"}],"x":200,"y":80,"wires":[["b46e7e0a.fef1f"]]},{"id":"7f828b55b50ff0e0","type":"junction","z":"e619260f6fbd83a2","x":400,"y":170,"wires":[[]]},{"id":"6cdd0bc8.b8e434","type":"server","name":"HA MaXyM","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"numeric","statusMonth":"2-digit","statusDay":"2-digit","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true},{"id":"affb329d.8fa8f","type":"switch","z":"bcb4b1c6.803708","name":"zero or more","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"0","vt":"str"},{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":710,"y":220,"wires":[["ee603327.68635","1925901bf1f7ce40"],["fcfa14ef.2feb28","1925901bf1f7ce40"]]},{"id":"b78f8102543d36f1","type":"subflow:e619260f6fbd83a2","z":"bcb4b1c6.803708","name":"","x":230,"y":160,"wires":[["ae0f2f18.6cbb7"]]},{"id":"ee603327.68635","type":"api-call-service","z":"bcb4b1c6.803708","name":"Occupied","server":"6cdd0bc8.b8e434","version":7,"debugenabled":false,"action":"input_boolean.turn_on","floorId":[],"areaId":[],"deviceId":[],"entityId":["input_boolean.home_occupied"],"labelId":[],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","blockInputOverrides":false,"domain":"input_boolean","service":"turn_on","x":960,"y":140,"wires":[[]]},{"id":"fcfa14ef.2feb28","type":"api-call-service","z":"bcb4b1c6.803708","name":"NOT Occupied","server":"6cdd0bc8.b8e434","version":7,"debugenabled":false,"action":"input_boolean.turn_off","floorId":[],"areaId":[],"deviceId":[],"entityId":["input_boolean.home_occupied"],"labelId":[],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","blockInputOverrides":false,"domain":"input_boolean","service":"turn_off","x":980,"y":200,"wires":[[]]},{"id":"d46b853a.df0c78","type":"server-state-changed","z":"bcb4b1c6.803708","name":"Some person state changed","server":"6cdd0bc8.b8e434","version":6,"outputs":1,"exposeAsEntityConfig":"","entities":{"entity":[],"substring":[],"regex":["person\\.*"]},"outputInitially":true,"stateType":"str","ifState":"","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":true,"for":"0","forType":"num","forUnits":"minutes","outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":200,"y":220,"wires":[["ae0f2f18.6cbb7"]]},{"id":"ae0f2f18.6cbb7","type":"ha-get-entities","z":"bcb4b1c6.803708","name":"How many persons in house","server":"6cdd0bc8.b8e434","version":1,"rules":[{"property":"entity_id","logic":"is","value":"person\\.*","valueType":"re"},{"property":"state","logic":"is","value":"home","valueType":"str"}],"outputType":"count","outputEmptyResults":false,"outputLocationType":"msg","outputLocation":"payload","outputResultsCount":1,"x":480,"y":220,"wires":[["affb329d.8fa8f"]]},{"id":"1925901bf1f7ce40","type":"ha-binary-sensor","z":"bcb4b1c6.803708","name":"House Occupied","entityConfig":"18bfb8bd.6da1c7","version":0,"state":"payload","stateType":"msg","attributes":[],"inputOverride":"allow","outputProperties":[],"x":980,"y":260,"wires":[[]]},{"id":"18bfb8bd.6da1c7","type":"ha-entity-config","server":"6cdd0bc8.b8e434","deviceConfig":"","name":"binary sensor config for House Occupied","version":6,"entityType":"binary_sensor","haConfig":[{"property":"name","value":"House Occupied"},{"property":"device_class","value":"occupancy"},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"resend":true}]

Sorry Biscuit Geoff, no cigar I am afraid!
I added a load of debugs, even if one or all of the TRVs are ‘on’, debug15 is still false.

Even at debug11 it is all false.

Here is my modded program.

[{"id":"36d4ef3de298894f","type":"api-call-service","z":"73559c302ea705e3","name":"Turn on Boiler Switch","server":"b9a48d8e.e88e9","version":7,"debugenabled":false,"action":"switch.turn_on","floorId":[],"areaId":[],"deviceId":[],"entityId":["switch.boiler_control_l1"],"labelId":[],"data":"{}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","blockInputOverrides":false,"domain":"switch","service":"turn_on","mergecontext":"","x":900,"y":400,"wires":[[]]},{"id":"3f9656bc7712c5ab","type":"api-call-service","z":"73559c302ea705e3","name":"Turn off Boiler Switch","server":"b9a48d8e.e88e9","version":7,"debugenabled":false,"action":"switch.turn_off","floorId":[],"areaId":[],"deviceId":[],"entityId":["switch.boiler_control_l1"],"labelId":[],"data":"{}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","blockInputOverrides":false,"domain":"switch","service":"turn_off","mergecontext":"","x":900,"y":460,"wires":[[]]},{"id":"824da4c33655a324","type":"server-state-changed","z":"73559c302ea705e3","name":"Any Change?","server":"b9a48d8e.e88e9","version":6,"outputs":1,"exposeAsEntityConfig":"","entities":{"entity":[],"substring":[],"regex":["climate"]},"outputInitially":true,"stateType":"str","ifState":"","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":true,"ignoreCurrentStateUnavailable":true,"outputProperties":[{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":70,"y":180,"wires":[["71dd1e8d912e36a6"]]},{"id":"33622da626b65eda","type":"api-current-state","z":"73559c302ea705e3","name":"","server":"b9a48d8e.e88e9","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"climate.hall_rad","state_type":"str","blockInputOverrides":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":310,"y":240,"wires":[["81df7b7549447cd3"]]},{"id":"71dd1e8d912e36a6","type":"api-current-state","z":"73559c302ea705e3","name":"","server":"b9a48d8e.e88e9","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"climate.living_rad","state_type":"str","blockInputOverrides":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":310,"y":180,"wires":[["a88aed54fdea4254"]]},{"id":"a88aed54fdea4254","type":"change","z":"73559c302ea705e3","name":"","rules":[{"t":"set","p":"trv","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"trv.living","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":180,"wires":[["33622da626b65eda","5796676375503c66"]]},{"id":"81df7b7549447cd3","type":"change","z":"73559c302ea705e3","name":"","rules":[{"t":"set","p":"trv.hall","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":240,"wires":[["1a7c1459e5a9227e","f1deb036beb4c6b6"]]},{"id":"4ca39ba6698c74dc","type":"change","z":"73559c302ea705e3","name":"Turn on or off","rules":[{"t":"set","p":"payload","pt":"msg","to":"\"heat\" in items.*","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":810,"y":300,"wires":[["88b22456e9b6170c","855b5f8c8095e9d0"]]},{"id":"88b22456e9b6170c","type":"delay","z":"73559c302ea705e3","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"2","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"allowrate":false,"outputs":1,"x":460,"y":420,"wires":[["439eb90548e9a947","0f3e556b0d415536"]]},{"id":"439eb90548e9a947","type":"switch","z":"73559c302ea705e3","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":670,"y":420,"wires":[["36d4ef3de298894f","3f9656bc7712c5ab","e4ee99d1426e4fc7"]]},{"id":"1a7c1459e5a9227e","type":"api-current-state","z":"73559c302ea705e3","name":"","server":"b9a48d8e.e88e9","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"climate.study_rad","state_type":"str","blockInputOverrides":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":310,"y":300,"wires":[["3ce251874e3ad1c1"]]},{"id":"3ce251874e3ad1c1","type":"change","z":"73559c302ea705e3","name":"","rules":[{"t":"set","p":"trv.study","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":300,"wires":[["4ca39ba6698c74dc","bda2cf0bfa47623e"]]},{"id":"855b5f8c8095e9d0","type":"debug","z":"73559c302ea705e3","name":"debug 11","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":960,"y":260,"wires":[]},{"id":"5796676375503c66","type":"debug","z":"73559c302ea705e3","name":"debug 12","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":920,"y":100,"wires":[]},{"id":"f1deb036beb4c6b6","type":"debug","z":"73559c302ea705e3","name":"debug 13","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":920,"y":160,"wires":[]},{"id":"bda2cf0bfa47623e","type":"debug","z":"73559c302ea705e3","name":"debug 14","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":920,"y":220,"wires":[]},{"id":"0f3e556b0d415536","type":"debug","z":"73559c302ea705e3","name":"debug 15","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":640,"y":620,"wires":[]},{"id":"e4ee99d1426e4fc7","type":"debug","z":"73559c302ea705e3","name":"debug 16","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":880,"y":560,"wires":[]},{"id":"b9a48d8e.e88e9","type":"server","name":"Home Assistant","addon":true}]

I am having fun trying to understand what is going on and trying to see if I can solve it!

Kind Regards,
Paul.

Troon, that screenshot is exactly like mine
The attributes do not change in that page but I have been to another developer page and changed the text to ‘heat’ or ‘off’ and it controls the valve.

Yes, sorry I made the mistake of editing it after I had it working to make it easier for you.

The JSONata in the Turn on or off Change node should be

“heat” in trv.*

I changed the other nodes but missed that one.

Then you’re looking for the state of the valve, not any of its attributes, and the template should be:

{{ states.climate
  | selectattr('state', 'eq', 'heat')
  | list
  | count >= 1
}}
1 Like

Troon,
That works!

Now I need to get it to turn the switch on!

Everyday is a school day!

Straightforward HA automation will handle that.

alias: Boiler switch manager
triggers:
  - trigger: state
    entity_id: binary_sensor.YOUR_TEMPLATE_SENSOR
actions:
  - action: switch.turn_{{ trigger.to_state.state }}
    target:
      entity_id: switch.YOUR_BOILER_SWITCH

Hi I’m trying to do exactly the same thing as you I believe. Did you get this working with the aqara t2? I have got mine going by setting up two automations
One checks for trvs state going off to on which switches on l1 (in my case) and vice versa.