Current State node - If-Statement "in"

Hey all

I just moved all automations from Yaml to Nodered. So far so good.
Quite everything works fine. Now I saw in the Current State node, that it is possible in the If-Statement to choose “in”. Unfortuanately I couldn’t figure out, how to enter multiple values.

If anyone would have an example for such a statement I would appreciate this a lot.

Thanks and happy new year
philipp

Comma delimited list: Schlagen,normal

Use a get template node to get all the data you need
Screenshot from 2020-01-01 11-03-51
Screenshot from 2020-01-01 11-02-40

i use that with a state change node but the output only on state change node is unticked cause i’m not looking at its state but at the other changes in the entity
Screenshot from 2020-01-01 11-07-27

Happy New Year
and Welcome to You

Thanks Kermit

I thought I tried this before. But I tried it again. With comma delimited list the node is set to true, if the first value Matches, but not if the second or third after the first comma.

I tested it and it works as intended with it being an or condition. In my example, it should output each time you flip the input_boolean.

image

[{"id":"5a71186b.0e0768","type":"server-state-changed","z":"9ce184b.0f5bb78","name":"","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.test","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on,off","halt_if_type":"str","halt_if_compare":"includes","outputs":2,"output_only_on_state_change":true,"x":732,"y":384,"wires":[["b0392c16.f5a61"],[]]},{"id":"b0392c16.f5a61","type":"debug","z":"9ce184b.0f5bb78","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":982,"y":384,"wires":[]}]

It works for me -

aaaaaaaaarghhh sorry guys!
of course it works! I had spaces after the commas……. :see_no_evil:

Thanks a lot for your support! :+1:

I am trying to do something that is logically similar to this, seems straight forward enough, except my “current state” node doesn’t have “state location” and “entity location”. This is what mine looks like:

I am trying to determine what source (app) a fire tv is currently using. Basically this:


I want to reproduce this automation condition in Node-Red.

I can sort of do what I need to do with a “trigger: state” node but I need this as a secondary check, not the initial trigger.

You are using in. This means that there is more than 1 entry in source message like

[com.amazon.tv.launcher, com.amazon.fire, com.something.else]

Is that how the data from the message looks? If it is a single entry use is

The standard msg doesn’t say what it is, it just outputs a general state (idle, paused, playing). I’ve kind of gone down the path of making a decision based on “idle” but I am not sure that launcher is the only thing that can be idle, “paused” and “playing” are a lot more ambiguous as they can apply to most apps.

The attribute “source” actually holds the what is idle, paused or playing. This is what that native Home Assistant automation is looking at in the attachment above, here’s the YAML of that:

condition:
  - condition: state
    entity_id: media_player.fire_tv_living_room
    attribute: source
    state: com.amazon.tv.launcher

I have like 20 Fire TV devices around the house and want them to generally be in my idea of “idle” mode, which is basically a video slideshow with time and weather in the corner. I have routines that turn the TVs they are connected to on and off depending on if the routines think that’s where I am going. Basically the idea is to have all the rooms look occupied all the time when they are, and snoozed when they aren’t.

When this is mostly a problem is when Amazon decides it’s tired of waiting for my Fire devices to become their idea of idle so they can push an update. Of course my idea of “idle” and theirs are 2 very different things so they’re never in that state. This has gotten really frequent, and very random, so they all update at different times. This means I am annoyed by entering a room and it’s displaying some full screen promo (one of Amazon’s annoying updates) for something I have no interest in, Amazon’s stream d’jour they’re hawking. Last month it was trying to get me to subscribe to some channel for pre-schoolers, despite the fact that no children’s show has ever been played on any of my devices.

Then I have to walk across the room to get the remote and get it back to where I want it. You know automate the stupid stuff.

Oh and BTW, I’m pretty much a noob with Node-Red, only been playing around with it for a few weeks. My native automations were getting out of hand, fairly simple but lots of them. I have like 500+ devices in HA.

And no the “in” was just where it was when I did the screen capture, I was randomly trying stuff.

Where it says if state did you change that to is rather than in?

image

yes, and that is where you’ll get idle/paused/playing from. This is how it is now, in a workable, but not ideal state:

…and then that outputs into a long string of ADB nodes in a subflow that launches and navigates the app.

Place the entity in this flow, just the entity everything else blank and post the debug by choosing the little copy value icon and post it here

image

[{"id":"fd6d7d5c583be57d","type":"inject","z":"60f2d2277843c698","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":400,"y":2540,"wires":[["e88f34f8b54d48d3"]]},{"id":"e88f34f8b54d48d3","type":"api-current-state","z":"60f2d2277843c698","name":"","server":"","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"","state_type":"str","blockInputOverrides":false,"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":600,"y":2540,"wires":[["bc5e8e282e2b769e"]]},{"id":"bc5e8e282e2b769e","type":"debug","z":"60f2d2277843c698","name":"debug 181","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":830,"y":2540,"wires":[]}]

{“_msgid”:“60d49842f02d5521”,“payload”:“idle”,“topic”:“”,“data”:{“entity_id”:“media_player.wall_cube_adb”,“state”:“idle”,“attributes”:{“source_list”:[“com.amazon.tv.launcher”],“app_id”:“com.amazon.tv.launcher”,“source”:“com.amazon.tv.launcher”,“adb_response”:null,“hdmi_input”:null,“device_class”:“tv”,“entity_picture”:“/api/media_player_proxy/media_player.wall_cube_adb?token=459063489da880797e671d608a8dxxxxxx4e08178ce8a33fbe8fe19257c736f40&cache=e1a452xxxxxx14cf”,“friendly_name”:“Wall Cube ADB”,“supported_features”:22961},“context”:{“id”:“01HVCCRJQRKYCVRMCH5XM64XYW”,“parent_id”:null,“user_id”:null},“last_changed”:“2024-04-13T18:43:31.130Z”,“last_updated”:“2024-04-13T18:50:51.000Z”,“timeSinceChangedMs”:493095}}

This should work. I did not see that you were looking for an attribute. That needs to be defined in jsonata.

New/old state is only applicable to triggers. Here we look at the current state, so there is no before or after

[{"id":"ab162b552a732f7b","type":"api-current-state","z":"0a325c35fc29f44e","name":"","server":"6b1110b5.183a4","version":3,"outputs":2,"halt_if":"$entity().attributes.source = 'com.amazon.tv.launcher'","halt_if_type":"jsonata","halt_if_compare":"jsonata","entity_id":"media_player.wall_cube_adb","state_type":"str","blockInputOverrides":false,"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":590,"y":3660,"wires":[[],[]]},{"id":"6b1110b5.183a4","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

Awesome. Yes indeed that did the trick. Tried something like that, but like I said I’m a noob at Node-Red, so it was something like that, but obviously not that. :grin:

Now I just gotta make 19 more versions of that.

1 Like