Looking for a blocking node

This is the two flows that triggers by the movement of our kitchen TV.
The TV is hung up in the ceiling and pivots down, the sensor mpu6050 x detects the position the TV is in.
About -4 when in “off” position and about 8 when down in viewing mode.

The on sequence has state change node triggering when > 1 and the switch node makes sure it is less than 4.
The off sequence is limited to less than 6 and more than 3 in the state change node and switch node.

After the switch nodes I delay for three seconds and check the new value and in the function node I make sure the TV is going in the correct direction

//             current state             state change 
if (parseFloat(msg.payload2) > parseFloat(msg.payload)+0.2){
    return msg;
}

This means it has to “travel” at least 0.2 in three seconds, which it does.
By some reason I still get an issue where it turns on the TV and then it turns it back off again during the lowering of the TV and when it is in the viewing position (8).
It didn’t do this a week ago.

Now to the question.
Is there a node I can insert that stops all messages for a minute or until I reset it, but only when it comes from the other sequence?
It could block/stop until I reset it or have a “timeout” setting that enables the messages again.

So when the TV on or off command has been sent trigger some node in the start of the other sequence to make sure it can’t run.
I looked at trigger node but it doesn’t seem to be what I want since it either sends something or doesn’t.
Traffic light doesn’t seem to be it either.
It would be great if the node had two inputs, one just for settings and the other for messages. I think that is what I’m looking for.

Everything except the link out, which just triggers the Chromecast

[{"id":"afc82cbf887adc00","type":"server-state-changed","z":"341b64864f1ae744","name":"","server":"4bbca37b.1700ec","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.mpu6050_accel_x","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"1","halt_if_type":"num","halt_if_compare":"gt","outputs":2,"output_only_on_state_change":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":240,"y":140,"wires":[["3bcebaa36458666a"],[]]},{"id":"5ac11971ac6530a8","type":"api-current-state","z":"341b64864f1ae744","name":"","server":"4bbca37b.1700ec","version":2,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.tv","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":390,"y":220,"wires":[["7c7da31747d87f38"],["6247ff9fd1568205"]]},{"id":"d26fa51342100b18","type":"api-call-service","z":"341b64864f1ae744","name":"","server":"4bbca37b.1700ec","version":3,"debugenabled":false,"service_domain":"remote","service":"send_command","entityId":"remote.broadlink_4_remote","data":"{\t  \"device\": \"kok_tv\",\t  \"command\": \"power\"\t}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":860,"y":220,"wires":[["7a419747e53fa09a"]]},{"id":"4326adfa96f28944","type":"delay","z":"341b64864f1ae744","name":"","pauseType":"delay","timeout":"3","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"x":620,"y":140,"wires":[["a727c3c669ca795b"]]},{"id":"a727c3c669ca795b","type":"api-current-state","z":"341b64864f1ae744","name":"","server":"4bbca37b.1700ec","version":2,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.mpu6050_accel_x","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload2","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":860,"y":140,"wires":[["571fb9214a348d74"]]},{"id":"571fb9214a348d74","type":"function","z":"341b64864f1ae744","name":"","func":"if (parseFloat(msg.payload2) > parseFloat(msg.payload)+0.2){\n    return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":160,"y":220,"wires":[["5ac11971ac6530a8"]]},{"id":"7c7da31747d87f38","type":"delay","z":"341b64864f1ae744","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"10","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"allowrate":false,"x":640,"y":220,"wires":[["d26fa51342100b18"]]},{"id":"3bcebaa36458666a","type":"switch","z":"341b64864f1ae744","name":"","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"4","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":490,"y":140,"wires":[["4326adfa96f28944"]]},{"id":"2c1a4a7f1d0056b7","type":"server-state-changed","z":"341b64864f1ae744","name":"","server":"4bbca37b.1700ec","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.mpu6050_accel_x","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"6","halt_if_type":"num","halt_if_compare":"lt","outputs":2,"output_only_on_state_change":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":240,"y":480,"wires":[["ea0e8ddef1dcf984"],[]]},{"id":"8aeab795d9094f8a","type":"api-current-state","z":"341b64864f1ae744","name":"","server":"4bbca37b.1700ec","version":2,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.tv","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":570,"y":580,"wires":[["e615a481a255558c"],["747140ba04e06e1e"]]},{"id":"e615a481a255558c","type":"api-call-service","z":"341b64864f1ae744","name":"","server":"4bbca37b.1700ec","version":3,"debugenabled":false,"service_domain":"remote","service":"send_command","entityId":"remote.broadlink_4_remote","data":"{\t  \"device\": \"kok_tv\",\t  \"command\": \"power\"\t}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":880,"y":580,"wires":[["747140ba04e06e1e"]]},{"id":"747140ba04e06e1e","type":"api-current-state","z":"341b64864f1ae744","name":"","server":"4bbca37b.1700ec","version":2,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is_not","entity_id":"media_player.chromecast_kok","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":610,"y":660,"wires":[["156d352a3874feef"],[]]},{"id":"156d352a3874feef","type":"api-call-service","z":"341b64864f1ae744","name":"","server":"4bbca37b.1700ec","version":3,"debugenabled":false,"service_domain":"media_player","service":"turn_off","entityId":"media_player.chromecast_kok","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":920,"y":660,"wires":[[]]},{"id":"a16b05c0f374f625","type":"delay","z":"341b64864f1ae744","name":"","pauseType":"delay","timeout":"3","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"x":620,"y":480,"wires":[["2e9ed4b1d16d61c8"]]},{"id":"2e9ed4b1d16d61c8","type":"api-current-state","z":"341b64864f1ae744","name":"","server":"4bbca37b.1700ec","version":2,"outputs":1,"halt_if":"","halt_if_type":"num","halt_if_compare":"is","entity_id":"sensor.mpu6050_accel_x","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload2","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":860,"y":480,"wires":[["f81c96b96b413b79"]]},{"id":"f81c96b96b413b79","type":"function","z":"341b64864f1ae744","name":"","func":"if (parseFloat(msg.payload2) < parseFloat(msg.payload)+0.2){\n    return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":360,"y":580,"wires":[["8aeab795d9094f8a"]]},{"id":"ea0e8ddef1dcf984","type":"switch","z":"341b64864f1ae744","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"3","vt":"str"},{"t":"eq","v":"unavailable","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":490,"y":480,"wires":[["a16b05c0f374f625"],[]]},{"id":"7a419747e53fa09a","type":"delay","z":"341b64864f1ae744","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"minute","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"x":870,"y":300,"wires":[["13ff69ae312c95ef"]]},{"id":"6247ff9fd1568205","type":"change","z":"341b64864f1ae744","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":300,"wires":[["7a419747e53fa09a"]]},{"id":"c2cc7e458e20e984","type":"comment","z":"341b64864f1ae744","name":"Turn on","info":"","x":290,"y":60,"wires":[]},{"id":"ab7bd3b60211914c","type":"comment","z":"341b64864f1ae744","name":"Turn off","info":"","x":310,"y":400,"wires":[]},{"id":"4bbca37b.1700ec","type":"server","name":"Home Assistant","version":1,"legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

I might have figured out a solution.
I set a flow variable after I turn on/off the TV and this variable is used in a switch node in the start.

You can send enabled/disabled in a message to a trigger node.

e. I just checked to make sure and nothing comes out of either output when sending enable/disabled. I’m not sure why it’s outputting when you send a command.

image

Are you saying you have problems to distinguish whether sensor mpu is opening or closing?

I believe that is the issue.

I tried to add a “blocking” node using a switch node that looked at the flow variable set after the TV got turned on.
The variable stayed true for 60 seconds but still somehow the TV got turned off.

That seems to suggest it’s the TV on sequence that fires again and turns off the TV.

Sadly our laptop screen cracked today so I can’t debug the flow today.

How do you disable?
Payload “disable”?

I’m not home now but I’ll think it out

I don’t think nodes with multiple inputs exist. The only way you can check origin is using topic or any custom attribute. you can set them using change node, then use for making decisions later on.

Just curious. Why do you use the current state of the position to turn on the TV? why don’t you use the current state of the TV to turn up or down the pivot? do you always display the same content in that TV? do you use 2 remotes/switches? one for the pivot and another for the TV? If you used the state of the tv you would use only 1 remote… I guess I’m missing something

I’m using one remote.
I currently can’t control the pivoting mount from HA.
But once I get the parts I need then it will be integrated.

But now I press the remote to lower the TV and when it is lowered past the threshold it triggers this flow and sends calls Broadlink to turn on the TV and cast the news.
The TV doesn’t have a antenna or possibilities to see live TV, but the news is live over Chromecast and that is all that is needed in the kitchen anyways.

And when I flip up the TV the Broadlink turns off the TV and cast.

1 Like

Here is what the sequence looks like at the moment.

The first switch node has three options
True
False
Null

So if it’s false or null (not set) then it’s allowed to enter the sequence.
And the switch node variable is set in the turn off sequence just as you can see in this sequence out on the right.

After TV is on, set flow variable to block, wait 60 seconds, then set the variable back again.

I believe this would do it. Turn on command when it reaches position 4 while opening. Turn off command when it reaches position 3 while closing.

[{"id":"f0ef1b2c.b98d08","type":"server-state-changed","z":"ebd7f2e4.a2afc","name":"Trigger","server":"9405c3fe.d0a6c","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.mpu6050_accel_x","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,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":150,"y":1000,"wires":[["9990e81b.a8a8e8"]]},{"id":"9990e81b.a8a8e8","type":"switch","z":"ebd7f2e4.a2afc","name":"Opening or closing?","property":"data.new_state.state","propertyType":"msg","rules":[{"t":"gt","v":"data.old_state.state","vt":"str"},{"t":"lt","v":"data.old_state.state","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":340,"y":1000,"wires":[["1217faff.8d21d5"],["3a49343c.a010ac"]],"outputLabels":["Opening","Closing"]},{"id":"8e37d7a4.979ad8","type":"debug","z":"ebd7f2e4.a2afc","name":"Turn off command","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":1020,"wires":[],"inputLabels":["Turn "]},{"id":"708c5223.80c82c","type":"debug","z":"ebd7f2e4.a2afc","name":"Turn on command","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":980,"wires":[],"inputLabels":["Turn "]},{"id":"1217faff.8d21d5","type":"switch","z":"ebd7f2e4.a2afc","name":"pos 4?","property":"data.new_state.state","propertyType":"msg","rules":[{"t":"eq","v":"4","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":530,"y":980,"wires":[["708c5223.80c82c"]]},{"id":"3a49343c.a010ac","type":"switch","z":"ebd7f2e4.a2afc","name":"pos 3?","property":"data.new_state.state","propertyType":"msg","rules":[{"t":"eq","v":"3","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":530,"y":1020,"wires":[["8e37d7a4.979ad8"]]},{"id":"9405c3fe.d0a6c","type":"server","name":"Home Assistant","version":1,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Yes I know that would be the simple solution.
But because I don’t want one fixed position where it happens I want to avoid this solution.

The reason is that I want it to turn on while it’s on its way down, meaning early.
And I want it to turn off early when it’s on its way up.

I actually want to fine tune these numbers even more to overlap so that it switches on earlier and switches off earlier.
That makes it look better in my opinion.

just change the value of the positions… instead of pos 4 and 3, pos 1 and 6.

Then add what should happen at both ends (-1,8) I believe, just in case you change the direction of the pivot midway

That won’t work.
Because it starts at -4.
Enters 1 where it turns on the TV.
Then it keeps going to 6 where it turns it off and eventually settles at 8.

My flow won’t turn it off at 6, because it distinguishes whether it’s opening or closing. Give it a go.

That’s it just a payload of enable or disable.

Sorry then.
As I said our laptop screen is broken so I can’t do that today, i just looked at the image and tried to read the JSON.
Sorry if I misunderstood.

Give it a go. If you set pos 1 and 6, when going from -4 to 8, it will turn on at 1 but it won’t turn off at 6. The only problem you may find is if you, let’s say, set the pivot to opening mode, let it go past 1 and set the pivot to closing mode before reaching pos 6. It that case the TV would stay on even though it’s closing. To avoid that just set that at pos -4 it should always turn off if it is still on and at 8 it should always turn on if it is still off.

Something could be worked to polish that problem though

Ok, sorry for rambling, this one’s the best. You’ll be completely safe against changing pivot’s direction whithin the whole range and it’ll toggle the TV inmediatelly without delays.

[{"id":"f0ef1b2c.b98d08","type":"server-state-changed","z":"ebd7f2e4.a2afc","name":"Trigger","server":"9405c3fe.d0a6c","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.mpu6050_accel_x","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,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":150,"y":1000,"wires":[["9990e81b.a8a8e8"]]},{"id":"9990e81b.a8a8e8","type":"switch","z":"ebd7f2e4.a2afc","name":"Opening or closing?","property":"data.new_state.state","propertyType":"msg","rules":[{"t":"gt","v":"data.old_state.state","vt":"msg"},{"t":"lt","v":"data.old_state.state","vt":"msg"}],"checkall":"true","repair":false,"outputs":2,"x":340,"y":1000,"wires":[["1217faff.8d21d5"],["3a49343c.a010ac"]],"outputLabels":["Opening","Closing"]},{"id":"1217faff.8d21d5","type":"switch","z":"ebd7f2e4.a2afc","name":"pos >= 1?","property":"data.new_state.state","propertyType":"msg","rules":[{"t":"gte","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":540,"y":960,"wires":[["e72e47b8.f96498"]]},{"id":"3a49343c.a010ac","type":"switch","z":"ebd7f2e4.a2afc","name":"pos <= 6?","property":"data.new_state.state","propertyType":"msg","rules":[{"t":"lte","v":"6","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":540,"y":1040,"wires":[["647bfe48.bb3df"]]},{"id":"e72e47b8.f96498","type":"api-current-state","z":"ebd7f2e4.a2afc","name":"TV off?","server":"4bbca37b.1700ec","version":2,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.tv","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":680,"y":960,"wires":[["e7372b65.806418"],[]]},{"id":"647bfe48.bb3df","type":"api-current-state","z":"ebd7f2e4.a2afc","name":"TV on?","server":"4bbca37b.1700ec","version":2,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.tv","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":680,"y":1040,"wires":[["688eba0d.424b44"],[]]},{"id":"e7372b65.806418","type":"debug","z":"ebd7f2e4.a2afc","name":"Turn on command","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":870,"y":960,"wires":[]},{"id":"688eba0d.424b44","type":"debug","z":"ebd7f2e4.a2afc","name":"Turn off command","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":870,"y":1040,"wires":[]},{"id":"9405c3fe.d0a6c","type":"server","name":"Home Assistant","version":1,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"4bbca37b.1700ec","type":"server","name":"Home Assistant","version":1,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Full flow

[{"id":"89329aa2.3323f8","type":"server-state-changed","z":"ebd7f2e4.a2afc","name":"Trigger","server":"9405c3fe.d0a6c","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.mpu6050_accel_x","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,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":150,"y":1240,"wires":[["4dd1fb5e.d328d4"]]},{"id":"4dd1fb5e.d328d4","type":"switch","z":"ebd7f2e4.a2afc","name":"Opening or closing?","property":"data.new_state.state","propertyType":"msg","rules":[{"t":"gt","v":"data.old_state.state","vt":"msg"},{"t":"lt","v":"data.old_state.state","vt":"msg"}],"checkall":"true","repair":false,"outputs":2,"x":340,"y":1240,"wires":[["2a48d8d.8c77928"],["8bc7a989.da2a18"]],"outputLabels":["Opening","Closing"]},{"id":"2a48d8d.8c77928","type":"switch","z":"ebd7f2e4.a2afc","name":"pos >= 1?","property":"data.new_state.state","propertyType":"msg","rules":[{"t":"gte","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":540,"y":1200,"wires":[["f7dfc6fd.816d08"]]},{"id":"8bc7a989.da2a18","type":"switch","z":"ebd7f2e4.a2afc","name":"pos <= 6?","property":"data.new_state.state","propertyType":"msg","rules":[{"t":"lte","v":"6","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":540,"y":1280,"wires":[["4c5f2661.428f18"]]},{"id":"f7dfc6fd.816d08","type":"api-current-state","z":"ebd7f2e4.a2afc","name":"TV off?","server":"4bbca37b.1700ec","version":2,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.tv","state_type":"str","blockInputOverrides":true,"outputProperties":[],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":680,"y":1200,"wires":[["947c1e1c.93708"],[]]},{"id":"4c5f2661.428f18","type":"api-current-state","z":"ebd7f2e4.a2afc","name":"TV on?","server":"4bbca37b.1700ec","version":2,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.tv","state_type":"str","blockInputOverrides":true,"outputProperties":[],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":680,"y":1280,"wires":[["7af24df7.582134"],[]]},{"id":"947c1e1c.93708","type":"api-call-service","z":"ebd7f2e4.a2afc","name":"TV on","server":"4bbca37b.1700ec","version":3,"debugenabled":false,"service_domain":"remote","service":"send_command","entityId":"remote.broadlink_4_remote","data":"{\t  \"device\": \"kok_tv\",\t  \"command\": \"power\"\t}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":810,"y":1200,"wires":[["7015dfbd.3b8c8"]]},{"id":"7015dfbd.3b8c8","type":"link out","z":"ebd7f2e4.a2afc","name":"Chromecast","links":[],"x":905,"y":1200,"wires":[]},{"id":"d0860bce.3362e8","type":"api-call-service","z":"ebd7f2e4.a2afc","name":"Chromecast off","server":"4bbca37b.1700ec","version":3,"debugenabled":false,"service_domain":"media_player","service":"turn_off","entityId":"media_player.chromecast_kok","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":960,"y":1280,"wires":[[]]},{"id":"7af24df7.582134","type":"api-call-service","z":"ebd7f2e4.a2afc","name":"TV off","server":"4bbca37b.1700ec","version":3,"debugenabled":false,"service_domain":"remote","service":"send_command","entityId":"remote.broadlink_4_remote","data":"{\t  \"device\": \"kok_tv\",\t  \"command\": \"power\"\t}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":810,"y":1280,"wires":[["d0860bce.3362e8"]]},{"id":"9405c3fe.d0a6c","type":"server","name":"Home Assistant","version":1,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"4bbca37b.1700ec","type":"server","name":"Home Assistant","version":1,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

The only issue I find that might happen with the two flows above relates to how fast your TV’s state updates in HA (and since you’re toggling it with a broadlink command, it’s likely it won’t be inmediate and it needs to be inmediate for the flow above to work properly). If the TV doesn’t update inmediately, you can either set an update_entity service call right before every TV current state check or, if that doesn’t work, this will for sure:

[{"id":"89329aa2.3323f8","type":"server-state-changed","z":"ebd7f2e4.a2afc","name":"Trigger","server":"9405c3fe.d0a6c","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.mpu6050_accel_x","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,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":150,"y":1240,"wires":[["4dd1fb5e.d328d4"]]},{"id":"4dd1fb5e.d328d4","type":"switch","z":"ebd7f2e4.a2afc","name":"Opening or closing?","property":"data.new_state.state","propertyType":"msg","rules":[{"t":"gt","v":"data.old_state.state","vt":"msg"},{"t":"lt","v":"data.old_state.state","vt":"msg"}],"checkall":"true","repair":false,"outputs":2,"x":340,"y":1240,"wires":[["2a48d8d.8c77928"],["8bc7a989.da2a18"]],"outputLabels":["Opening","Closing"]},{"id":"2a48d8d.8c77928","type":"switch","z":"ebd7f2e4.a2afc","name":"pos >= 1?","property":"data.new_state.state","propertyType":"msg","rules":[{"t":"gte","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":540,"y":1200,"wires":[["9ec121fd.e48bc"]]},{"id":"8bc7a989.da2a18","type":"switch","z":"ebd7f2e4.a2afc","name":"pos <= 6?","property":"data.new_state.state","propertyType":"msg","rules":[{"t":"lte","v":"6","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":540,"y":1280,"wires":[["4c798342.c556bc"]]},{"id":"947c1e1c.93708","type":"api-call-service","z":"ebd7f2e4.a2afc","name":"TV on","server":"4bbca37b.1700ec","version":3,"debugenabled":false,"service_domain":"remote","service":"send_command","entityId":"remote.broadlink_4_remote","data":"{\t  \"device\": \"kok_tv\",\t  \"command\": \"power\"\t}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":910,"y":1200,"wires":[["7015dfbd.3b8c8"]]},{"id":"7015dfbd.3b8c8","type":"link out","z":"ebd7f2e4.a2afc","name":"Chromecast","links":[],"x":1005,"y":1200,"wires":[]},{"id":"d0860bce.3362e8","type":"api-call-service","z":"ebd7f2e4.a2afc","name":"Chromecast off","server":"4bbca37b.1700ec","version":3,"debugenabled":false,"service_domain":"media_player","service":"turn_off","entityId":"media_player.chromecast_kok","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1060,"y":1280,"wires":[[]]},{"id":"7af24df7.582134","type":"api-call-service","z":"ebd7f2e4.a2afc","name":"TV off","server":"4bbca37b.1700ec","version":3,"debugenabled":false,"service_domain":"remote","service":"send_command","entityId":"remote.broadlink_4_remote","data":"{\t  \"device\": \"kok_tv\",\t  \"command\": \"power\"\t}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":910,"y":1280,"wires":[["d0860bce.3362e8"]]},{"id":"9ec121fd.e48bc","type":"switch","z":"ebd7f2e4.a2afc","name":"","property":"pivot","propertyType":"flow","rules":[{"t":"neq","v":"opening","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":635,"y":1200,"wires":[["d8540f5c.99964"]],"l":false},{"id":"d8540f5c.99964","type":"change","z":"ebd7f2e4.a2afc","name":"set to opening","rules":[{"t":"set","p":"pivot","pt":"flow","to":"opening","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":760,"y":1200,"wires":[["947c1e1c.93708"]]},{"id":"4c798342.c556bc","type":"switch","z":"ebd7f2e4.a2afc","name":"","property":"pivot","propertyType":"flow","rules":[{"t":"neq","v":"closing","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":635,"y":1280,"wires":[["7eba6d61.d75324"]],"l":false},{"id":"7eba6d61.d75324","type":"change","z":"ebd7f2e4.a2afc","name":"set to closing","rules":[{"t":"set","p":"pivot","pt":"flow","to":"closing","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":750,"y":1280,"wires":[["7af24df7.582134"]]},{"id":"9405c3fe.d0a6c","type":"server","name":"Home Assistant","version":1,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"4bbca37b.1700ec","type":"server","name":"Home Assistant","version":1,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]