Node Red: Comparing two messages

This flow is constructed to monitor the couch presence while something is playing, and if a person leaves, the content will pause. When the person returns, the content will resume.

I’m stuck on this last piece. I need to compare two values (Get initial person count, and Get paused person count; msg.initialcouch and msg.pausedcouch respectively). By the time I’m comparing the values, the msg.initialcouch is no longer available to compare. Because it’s later in the flow, I’m missing something that allows me to compare the two. Once compared, I want to validate that msg.initialcouch and msg.pausedcouch match, and then resume the media.

If anyone has any ideas, I’d be very grateful!

You will want to use a function node and do something like this:

const states = global.get('homeassistant').homeAssistant.states;
const initial = states['input_number.initial_person_count'].state;
const paused = states['input_number.paused_person_count'].state;
var newMSG={};
if (initial == paused)
{
    newMSG.payload = "equal"
}
else
{
    newMSG.payload = "not equal"
}
return newMSG;

You can then use a switch node after this to check the property of msg.payload and check for equal or not equal…

There are probably better ways to do this… Also, I don’t know what type of entities you are using for your counts.

1 Like

Man, that’s super helpful. Appreciate the response.

The values are from an image processing scan that takes place in the “re/analyze camera feed”, then takes the state from that image processing entity in the next node.

How would you suggest to get those person_count entities differently so I can reference them later?

So, the numbers are captured real-time from the camera but not currently stored in a variable or entity, right? This means, you are grabbing the state at one point and then grabbing the state of the same entity at another time, right?

If that is the case, then we will definitely want to save each state into a flow variable and use a function to compare them.

I am not home ATM so just typing from my phone but if my above guesses were accurate then do some quick reading on variables, you’ll be interested in a “flow object”. You’ll set two different flow objects at different times and then compare them.

Yes, you’ve got it. Basically grabbing the value from the image_processing entity at the time of capture and not storing it anywhere but the msg itself.

Through my digging I came across the flow and global variables, both of which I played around. I attempted to change the msg.initialcouch to flow.initialcouch and then did a comparison in the function “Compare initial and paused number of people” like this:

newmsg = {};
if (flow.initialcouch == msg.pausecouch) {
    newmsg.payload = "True";
} else {
    newmsg.payload = "False";
}
return newmsg;

This didn’t work for me, and I ended up giving up that route. Where do you think I was going wrong with the flow variable?

I’d be curious if the data types you were comparing are congruent. You might do a

node.warn(msg.pausecouch)

And the same for the other to see what data is being passed. You can do that in a function node.

I’ve never used a node.warn before, so let me if you think I’ve done it incorrectly. I just brought these nodes out to run a quick test without going through the full flow.

Both nodes are set up like this, with their respective msg’s:

Screenshot (25)

Both output this in the debug node:

Screenshot (26)

You should be able to call both warns from the same function node that way you can check the debug output for both at the same time. This will let you ensure the data types are the same.

I changed the function node to

node.warn(msg.pausecouch)
node.warn(msg.initialcouch)
return msg;

which gave me the same output as above.

I’m thinking about going with the direction you gave in the initial example. I think I could set the image_processing values to input_numbers entities, and then reference those later, instead of the msg’s. Think that would be a better bet?

Post your code/export and I’ll have a look in the morning.

Do you know where in the flow you are losing the msg.initialcouch? If you don’t overwrite that property it should stay in the message as it travels through the flow.

I have several flows where I write to to a message property I have named msg.current_date. This value holds through the flow and I check it using the switch node (see below)

image

Thanks a lot for looking, here is the export:

[{"id":"47c2747a.25f804","type":"server-state-changed","z":"2ad01d0e.c8e852","name":"Shield playing anything","server":"48b6dc20.3e4a34","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"media_player.shield","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":120,"y":2560,"wires":[["a62a4d5.aac0fb"]]},{"id":"ef70b036.c403a8","type":"api-call-service","z":"2ad01d0e.c8e852","name":"Analyze Camera Feed","server":"48b6dc20.3e4a34","version":1,"debugenabled":false,"service_domain":"image_processing","service":"scan","entityId":"image_processing.deepstack_person_detector","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":560,"y":2560,"wires":[["5eee1d85.abf46c"]]},{"id":"2d564e3f.212dda","type":"delay","z":"2ad01d0e.c8e852","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1380,"y":2520,"wires":[["46d4cfac.e6319"]]},{"id":"4f551d07.a32ed4","type":"api-current-state","z":"2ad01d0e.c8e852","name":"Get current person count","server":"48b6dc20.3e4a34","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is_not","override_topic":false,"entity_id":"image_processing.deepstack_person_detector","state_type":"str","state_location":"currentcouch","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1950,"y":2520,"wires":[["4798aa36.916bb4"]]},{"id":"4798aa36.916bb4","type":"switch","z":"2ad01d0e.c8e852","name":"Compare with initial on-couch presence","property":"currentcouch","propertyType":"msg","rules":[{"t":"lt","v":"initialcouch","vt":"msg"},{"t":"eq","v":"initialcouch","vt":"msg"},{"t":"eq","v":"unknown","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":2280,"y":2520,"wires":[["f5d8a162.e09f8"],["2d564e3f.212dda"],["2d564e3f.212dda"]]},{"id":"48cba68e.bcaa","type":"switch","z":"2ad01d0e.c8e852","name":"Make sure couch isn't empty","property":"initialcouch","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"unknown","vt":"str"},{"t":"gt","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":1140,"y":2540,"wires":[[],[],["2d564e3f.212dda"]]},{"id":"46d4cfac.e6319","type":"api-call-service","z":"2ad01d0e.c8e852","name":"Re-analyze Camera Feed","server":"48b6dc20.3e4a34","version":1,"debugenabled":false,"service_domain":"image_processing","service":"scan","entityId":"image_processing.deepstack_person_detector","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1650,"y":2520,"wires":[["4f551d07.a32ed4"]]},{"id":"4fccabb4.9f5644","type":"delay","z":"2ad01d0e.c8e852","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":2240,"y":2620,"wires":[["514aaa20.5e7a8c"]]},{"id":"c89bfb57.de34d8","type":"api-current-state","z":"2ad01d0e.c8e852","name":"Get paused person count","server":"48b6dc20.3e4a34","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"image_processing.deepstack_person_detector","state_type":"str","state_location":"pausecouch","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1650,"y":2700,"wires":[["1330be7.096b042"]]},{"id":"514aaa20.5e7a8c","type":"api-call-service","z":"2ad01d0e.c8e852","name":"Re-analyze Camera Feed","server":"48b6dc20.3e4a34","version":1,"debugenabled":false,"service_domain":"image_processing","service":"scan","entityId":"image_processing.deepstack_person_detector","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":2450,"y":2620,"wires":[["c89bfb57.de34d8"]]},{"id":"aca704e.06a4678","type":"api-current-state","z":"2ad01d0e.c8e852","name":"Check to ensure still paused","server":"48b6dc20.3e4a34","version":1,"outputs":2,"halt_if":"paused","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"media_player.shield","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":2500,"y":2700,"wires":[["3684c5e7.a12732"],[]]},{"id":"3684c5e7.a12732","type":"api-call-service","z":"2ad01d0e.c8e852","name":"Resume","server":"48b6dc20.3e4a34","version":1,"debugenabled":false,"service_domain":"media_player","service":"media_play","entityId":"media_player.shield","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":2720,"y":2700,"wires":[[]]},{"id":"f5d8a162.e09f8","type":"api-current-state","z":"2ad01d0e.c8e852","name":"Check to ensure still playing","server":"48b6dc20.3e4a34","version":1,"outputs":2,"halt_if":"playing","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"media_player.shield","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":2620,"y":2520,"wires":[["74401507.844acc"],[]]},{"id":"2a7556e1.23d962","type":"api-current-state","z":"2ad01d0e.c8e852","name":"Check to ensure still paused","server":"48b6dc20.3e4a34","version":1,"outputs":2,"halt_if":"paused","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"media_player.shield","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":2000,"y":2620,"wires":[["4fccabb4.9f5644"],[]]},{"id":"74401507.844acc","type":"api-call-service","z":"2ad01d0e.c8e852","name":"Pause","server":"48b6dc20.3e4a34","version":1,"debugenabled":false,"service_domain":"media_player","service":"media_pause","entityId":"media_player.shield","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":2830,"y":2520,"wires":[["c5da0dae.742cc"]]},{"id":"c5da0dae.742cc","type":"trigger-state","z":"2ad01d0e.c8e852","name":"Wait for state to change to paused","server":"48b6dc20.3e4a34","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"media_player.shield","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"rd9wqvei7k","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"paused"},{"id":"i2a95d1givs","targetType":"this_entity","targetValue":"","propertyType":"previous_state","propertyValue":"old_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"playing"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":1680,"y":2620,"wires":[["2a7556e1.23d962"],[]]},{"id":"a62a4d5.aac0fb","type":"switch","z":"2ad01d0e.c8e852","name":"Playing State","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"playing","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":350,"y":2560,"wires":[["ef70b036.c403a8"]]},{"id":"5eee1d85.abf46c","type":"api-current-state","z":"2ad01d0e.c8e852","name":"Get initial person count","server":"48b6dc20.3e4a34","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is_not","override_topic":false,"entity_id":"image_processing.deepstack_person_detector","state_type":"str","state_location":"initialcouch","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":860,"y":2540,"wires":[["48cba68e.bcaa"]]},{"id":"9dc663e3.c7ab08","type":"switch","z":"2ad01d0e.c8e852","name":"Is it Time?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"True","vt":"str"},{"t":"eq","v":"False","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":2270,"y":2700,"wires":[["aca704e.06a4678"],[]]},{"id":"1330be7.096b042","type":"function","z":"2ad01d0e.c8e852","name":"Compare initial and paused number of people","func":"newmsg = {};\nif (msg.initialcouch == msg.pausecouch) {\n    newmsg.payload = \"True\";\n} else {\n    newmsg.payload = \"False\";\n}\n\nreturn newmsg;","outputs":1,"noerr":0,"x":1990,"y":2700,"wires":[["9dc663e3.c7ab08"]]},{"id":"48b6dc20.3e4a34","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

From my testing, I’ve found that the “Compare with initial on-couch presence” works fine, but by the time I’m past “Wait for state to change to paused”, I no longer have the message property. If I bypass that line of nodes, then I believe I can compare the two messages.

I would try a couple things in terms of debugging first.

  1. Add another person into your testing equation here and see if you can get your warn.debug statements to present different numbers for initial and pause. Right now we can’t tell whether or not values are being overwritten or if they are in fact different numbers (they just happen to both be ‘1’).

If the above works and you get back a ‘X’ and ‘Y’ then we know your direction works and just needs some refinement. Otherwise, you could try setting variables OR adding in input_number entities into HA and setting your counts to those. Just some options.

The trigger-state node’s input is really only used for testing and to enable/disable the node. I don’t think it’s doing what you think it’s doing.

Not really tested but might get you some different ideas.

[{"id":"cdb5e262.9fc2","type":"api-call-service","z":"ffbd7f06.4a014","name":"Analyze Camera Feed","version":1,"debugenabled":false,"service_domain":"image_processing","service":"scan","entityId":"image_processing.deepstack_person_detector","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":388,"y":928,"wires":[["d1499446.afc6a8"]]},{"id":"d1499446.afc6a8","type":"api-current-state","z":"ffbd7f06.4a014","name":"Get person count","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"image_processing.deepstack_person_detector","state_type":"num","state_location":"payload","override_payload":"msg","entity_location":"","override_data":"none","blockInputOverrides":false,"x":602,"y":928,"wires":[["9f21e19c.01a3f"]]},{"id":"d6c340a9.de0ea","type":"trigger-state","z":"ffbd7f06.4a014","name":"Shield starts playing","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"media_player.shield","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"n22z5a8wi3","targetType":"this_entity","targetValue":"","propertyType":"previous_state","propertyValue":"old_state.state","comparatorType":"is_not","comparatorValueDatatype":"str","comparatorValue":"playing"},{"id":"o1or2annat","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"playing"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":164,"y":832,"wires":[["f67362ce.c6278"],[]]},{"id":"f67362ce.c6278","type":"api-call-service","z":"ffbd7f06.4a014","name":"Analyze Camera Feed","version":1,"debugenabled":false,"service_domain":"image_processing","service":"scan","entityId":"image_processing.deepstack_person_detector","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":388,"y":832,"wires":[["af74aff6.3167a"]]},{"id":"af74aff6.3167a","type":"api-current-state","z":"ffbd7f06.4a014","name":"Get initial person count","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is_not","override_topic":false,"entity_id":"image_processing.deepstack_person_detector","state_type":"str","state_location":"initialcouch","override_payload":"flow","entity_location":"","override_data":"none","blockInputOverrides":false,"x":612,"y":832,"wires":[[]]},{"id":"ac8933eb.711bc","type":"comment","z":"ffbd7f06.4a014","name":"Set initial person count when shield starts playing","info":"","x":244,"y":784,"wires":[]},{"id":"974d044e.dcf688","type":"poll-state","z":"ffbd7f06.4a014","name":"Shield playing anything","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"10","updateIntervalUnits":"seconds","outputinitially":false,"outputonchanged":false,"entity_id":"media_player.shield","state_type":"str","halt_if":"playing, paused","halt_if_type":"str","halt_if_compare":"includes","outputs":2,"x":164,"y":928,"wires":[["cdb5e262.9fc2"],[]]},{"id":"2aef930a.32d25c","type":"comment","z":"ffbd7f06.4a014","name":"Poll Shield every 10 seconds to see if person count has changed and pause or resume","info":"","x":364,"y":880,"wires":[]},{"id":"be668d6f.f3b65","type":"api-current-state","z":"ffbd7f06.4a014","name":"Check to ensure still playing","version":1,"outputs":2,"halt_if":"playing","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"media_player.shield","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1064,"y":928,"wires":[["c7d668c2.638ce8"],[]]},{"id":"c7d668c2.638ce8","type":"api-call-service","z":"ffbd7f06.4a014","name":"Pause","version":1,"debugenabled":false,"service_domain":"media_player","service":"media_pause","entityId":"media_player.shield","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1266,"y":928,"wires":[[]]},{"id":"9f21e19c.01a3f","type":"switch","z":"ffbd7f06.4a014","name":"Compare person count","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"initialcouch","vt":"flow"},{"t":"eq","v":"initialcouch","vt":"flow"}],"checkall":"true","repair":false,"outputs":2,"x":820,"y":928,"wires":[["be668d6f.f3b65"],["57ce1421.d747ac"]]},{"id":"57ce1421.d747ac","type":"api-current-state","z":"ffbd7f06.4a014","name":"Check to ensure still paused","version":1,"outputs":2,"halt_if":"paused","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"media_player.shield","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1064,"y":976,"wires":[["487fcff1.4c8f3"],[]]},{"id":"487fcff1.4c8f3","type":"api-call-service","z":"ffbd7f06.4a014","name":"Resume","version":1,"debugenabled":false,"service_domain":"media_player","service":"media_play","entityId":"media_player.shield","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1276,"y":976,"wires":[[]]}]
2 Likes

I’ll give these both a try later tonight and report back. Options are good, appreciate it!!

This is amazing, way simpler and easier to debug. The playing / pausing works flawlessly, but now the playing is dependent on the # of people on the couch. If someone manually pauses the media, but remain sitting on the couch, it will resume the media automatically since the person count is the same. That’s why I initially made it all one (albeit long) flow.

Any ideas on how I can get around that stumbling block?

There’s probably a better way to do this but it was the first thing that popped into my head. Another option is if you’re connecting NR to HA using a separate “Node-RED” user you could check the context value to see what user paused the shield and just use that as a conditional.

[{"id":"a3108562.9f8238","type":"api-call-service","z":"ffbd7f06.4a014","name":"Analyze Camera Feed","version":1,"debugenabled":false,"service_domain":"image_processing","service":"scan","entityId":"image_processing.deepstack_person_detector","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":388,"y":1088,"wires":[["12057244.0baabe"]]},{"id":"12057244.0baabe","type":"api-current-state","z":"ffbd7f06.4a014","name":"Get person count","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"image_processing.deepstack_person_detector","state_type":"num","state_location":"payload","override_payload":"msg","entity_location":"","override_data":"none","blockInputOverrides":false,"x":602,"y":1088,"wires":[["50e3f0ea.d5244"]]},{"id":"1fe9fb5e.d8bfe5","type":"trigger-state","z":"ffbd7f06.4a014","name":"Shield starts playing","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"media_player.shield","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"n22z5a8wi3","targetType":"this_entity","targetValue":"","propertyType":"previous_state","propertyValue":"old_state.state","comparatorType":"is_not","comparatorValueDatatype":"str","comparatorValue":"playing"},{"id":"o1or2annat","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"playing"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":164,"y":992,"wires":[["d2c907be.784798"],[]]},{"id":"d2c907be.784798","type":"api-call-service","z":"ffbd7f06.4a014","name":"Analyze Camera Feed","version":1,"debugenabled":false,"service_domain":"image_processing","service":"scan","entityId":"image_processing.deepstack_person_detector","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":388,"y":992,"wires":[["2d0877c1.24d288"]]},{"id":"2d0877c1.24d288","type":"api-current-state","z":"ffbd7f06.4a014","name":"Get initial person count","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is_not","override_topic":false,"entity_id":"image_processing.deepstack_person_detector","state_type":"str","state_location":"initialcouch","override_payload":"flow","entity_location":"","override_data":"none","blockInputOverrides":false,"x":612,"y":992,"wires":[[]]},{"id":"19cf41cd.02cd6e","type":"comment","z":"ffbd7f06.4a014","name":"Set initial person count when shield starts playing","info":"","x":244,"y":944,"wires":[]},{"id":"c6a9bde5.16795","type":"poll-state","z":"ffbd7f06.4a014","name":"Shield playing anything","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"updateinterval":"10","updateIntervalUnits":"seconds","outputinitially":false,"outputonchanged":false,"entity_id":"media_player.shield","state_type":"str","halt_if":"playing, paused","halt_if_type":"str","halt_if_compare":"includes","outputs":2,"x":164,"y":1088,"wires":[["a3108562.9f8238","db9b0f2b.dac12"],[]]},{"id":"7a21d14b.1463f","type":"comment","z":"ffbd7f06.4a014","name":"Poll Shield every 10 seconds to see if person count has changed and pause or resume","info":"","x":364,"y":1040,"wires":[]},{"id":"fcf82680.e330b8","type":"api-current-state","z":"ffbd7f06.4a014","name":"Check to ensure still playing","version":1,"outputs":2,"halt_if":"playing","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"media_player.shield","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1064,"y":1088,"wires":[["d908c0bf.c9df8","7d749ed3.3552b"],[]]},{"id":"d908c0bf.c9df8","type":"api-call-service","z":"ffbd7f06.4a014","name":"Pause","version":1,"debugenabled":false,"service_domain":"media_player","service":"media_pause","entityId":"media_player.shield","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1266,"y":1088,"wires":[[]]},{"id":"50e3f0ea.d5244","type":"switch","z":"ffbd7f06.4a014","name":"Compare person count","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"initialcouch","vt":"flow"},{"t":"eq","v":"initialcouch","vt":"flow"}],"checkall":"true","repair":false,"outputs":2,"x":820,"y":1088,"wires":[["fcf82680.e330b8"],["20950fde.584ad"]]},{"id":"43389796.648da8","type":"api-current-state","z":"ffbd7f06.4a014","name":"Check to ensure still paused","version":1,"outputs":2,"halt_if":"paused","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"media_player.shield","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1064,"y":1136,"wires":[["e996bbf4.b21428"],[]]},{"id":"e996bbf4.b21428","type":"api-call-service","z":"ffbd7f06.4a014","name":"Resume","version":1,"debugenabled":false,"service_domain":"media_player","service":"media_play","entityId":"media_player.shield","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1276,"y":1136,"wires":[[]]},{"id":"7d749ed3.3552b","type":"change","z":"ffbd7f06.4a014","name":"autoPaused true","rules":[{"t":"set","p":"autoPaused","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1296,"y":1040,"wires":[[]]},{"id":"db9b0f2b.dac12","type":"switch","z":"ffbd7f06.4a014","name":"reset autoPause if playing","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"playing","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":398,"y":1136,"wires":[["7013d9c0.a483d8"]]},{"id":"7013d9c0.a483d8","type":"change","z":"ffbd7f06.4a014","name":"autoPaused false","rules":[{"t":"set","p":"autoPaused","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":618,"y":1136,"wires":[[]]},{"id":"20950fde.584ad","type":"switch","z":"ffbd7f06.4a014","name":"autoPaused?","property":"autoPause","propertyType":"flow","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":854,"y":1136,"wires":[["43389796.648da8"]]}]
1 Like

Even if it isn’t the most elegant, this works exactly as I want it to. I’ll continue tweaking, but this is awesome, thank you!!! Saved me a ton of time.