RM4 Reemote device switching while monitoring state of other devices

I am replacing my harmony Hub with an RM4 transmitter, and know how to setup the cards for controling each of my nedia devices.
How ever I want to create an activity card so I can switch what equipment to use when an activety is selected.
I can create them indervidually to undertake the sequence thats required for example watch tv.
Turn Tv on
Set input to hdmi 2
Turn Sky Q on etc.
however what I need is a way when changing activity to a differnt device for instance to watch a movie on dvd, and checks if the tv is on or off prior to switching activity.
Is Tv on? yes then do nothing to tv power
else Turn Tv On
Turn DVD on
Set input to HDMI 1
Is Sky Q on? Yes then turn Sky Q off
else do noting.
I will probably us a toggle button card for each activity to trigget the sequence, and the card woud change it’s status if a different activity has been selected so when I have finished all activities i can toggle the active activity to switch everything off.
could anyone point me in the right direction on this please.
If it was visual basic I would have done this easily but on HA banging head againt wall. I am also not sure if the RM4 Reports back Status of a trigger, but assume not.

- type: conditional
    conditions:
      - entity: media_player.projector_tv
        state: playing
    card:
      type: custom:mini-media-player
      entity: media_player.projector_tv
      ...
      ...
      the card has other settings, not related to the conversation

The above makes my mini-media-player-card disappear on every other state except playing…
You can chain them with something like vertical stack card so that a different media player would turn up in the same spot… say ps4 for example.

You would need a script or automation for the actual action you want to perform if I am reading correctly

Thanks for that.
I was looking at some sort of script that stored the state of a device on or off then call the scrip to check state. I think time to experiment.

The RM4 does not report back on the status of the devices it controls - it just blasts out commands with no way of knowing whether they’ve been received.

If you want HA to retain the assumed state of the devices it’s controlling you can represent them with input_boolean helpers and have the RM4 send commands when the helpers change state, or you can create switches out of the RM4 commands (see Broadlink docs).

One other Idea I have is to use MariaDB, and create a new table that has all RM4 devices listed with a status stored in the database.
This would have an advantage of restoring all devices to the last know state after power failure to the home, or return home assistant to last know state after reboot without sending triggers to the RM4.
I think this could be done via Node Red with the mysql connection. Time to studdy Node Red, and see what can be done.

HA sql docs

I don’t think I ever figured out how to INSERT in home assistant.
I did do it via nodered though… an example below to help you along.

msg.topic = "INSERT INTO Consumption(`TimeStamp`,`EnergyUsed`, `PowerUsed`) VALUES ('"+TimeStamp+"','"+EnergyUsed+"','"+PowerUsed+"')";
my dodgy outdated insert nodered flow

``` [{"id":"cdb5bad0b80fb740","type":"tab","label":"SBFspot insert mysql","disabled":true,"info":"","env":[]},{"id":"55a241febe3a5755","type":"mysql","z":"cdb5bad0b80fb740","mydb":"df28645b3bc41a9c","name":"insert SBFspot","x":1020,"y":200,"wires":[["bc21762ed999437d"]]},{"id":"5507e1a717da4c80","type":"inject","z":"cdb5bad0b80fb740","name":"TS Trigger","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"300","crontab":"","once":true,"onceDelay":"100","topic":"TimeStamp","payload":"","payloadType":"date","x":150,"y":140,"wires":[["51ea2a50706d1f4e","146ede6a00449568","cbb9399c767b3de3"]]},{"id":"146ede6a00449568","type":"api-current-state","z":"cdb5bad0b80fb740","name":"live consumption","server":"df1a2a65.adcab8","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.powerpal_live_consumption","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"topic","propertyType":"msg","value":"PowerUsed","valueType":"str"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":430,"y":100,"wires":[["e3fb4e247c0895a7"]]},{"id":"c3ebfe900c57e242","type":"debug","z":"cdb5bad0b80fb740","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":910,"y":40,"wires":[]},{"id":"51ea2a50706d1f4e","type":"api-current-state","z":"cdb5bad0b80fb740","name":"total consumption","server":"df1a2a65.adcab8","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.powerpal_total_consumption","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"topic","propertyType":"msg","value":"EnergyUsed","valueType":"str"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":390,"y":40,"wires":[["e3fb4e247c0895a7"]]},{"id":"e3fb4e247c0895a7","type":"function","z":"cdb5bad0b80fb740","name":"Unit convert *1000","func":"msg.payload = Number(msg.payload);\nmsg.payload = (msg.payload)*1000;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":650,"y":40,"wires":[["50c3dd4c2005358b"]]},{"id":"50c3dd4c2005358b","type":"join","z":"cdb5bad0b80fb740","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":650,"y":160,"wires":[["7e966461178798df"]]},{"id":"7e966461178798df","type":"function","z":"cdb5bad0b80fb740","name":"join payloads and insert","func":"var TimeStamp = msg.payload.TimeStamp\nvar EnergyUsed = msg.payload.EnergyUsed\nvar PowerUsed = msg.payload.PowerUsed\nmsg.topic = \"INSERT INTO Consumption(`TimeStamp`,`EnergyUsed`, `PowerUsed`) VALUES ('\"+TimeStamp+\"','\"+EnergyUsed+\"','\"+PowerUsed+\"')\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":810,"y":120,"wires":[["c3ebfe900c57e242","92878e2fc6feb5b1"]]},{"id":"bc21762ed999437d","type":"debug","z":"cdb5bad0b80fb740","name":"response","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1000,"y":280,"wires":[]},{"id":"cbb9399c767b3de3","type":"function","z":"cdb5bad0b80fb740","name":"convert TS milli to unix > /1000","func":"msg.payload = Number(msg.payload);\nmsg.payload = (msg.payload)/1000;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":180,"wires":[["50c3dd4c2005358b"]]},{"id":"92878e2fc6feb5b1","type":"debounce","z":"cdb5bad0b80fb740","time":"2000","name":"","x":800,"y":220,"wires":[["55a241febe3a5755"]]},{"id":"df28645b3bc41a9c","type":"MySQLdatabase","name":"","host":"127.0.0.1","port":"3306","db":"SBFspot","tz":"","charset":"UTF8"},{"id":"df1a2a65.adcab8","type":"server","name":"Home Assistant","version":4,"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":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m"}] ```