Turn on/off a device from a variable

I have a device name stored in a variable and am trying to turn on the device by using the variable string. Is that possible?
I'm storing all device updates in a file (device-name and date/time), and will be reading that file when i'm away to 'replay' my lights turning on/off based on the behavior 1 week back. (I'm transferring for another HA system, and used to have this set up working well before.) Hope it makes sense, and that someone can help.
(i've seen similar posts before, but since they're a bit old, things might have changed in the system)

Not sure (i might misunderstand your example):
I have a few devices (switch1, sw2, sw3). a trigger looks for changes in any of the devices, and every time a device changes the device name is stored in a variable.
I want to use that variable to turn on/off the switch.
Is this want you meant as well?

I'm not sure there's a way to directly select which device to control based upon a variable. I think you'll need some conditional logic to determine which device to control.

Was hoping to avoid to write one rule per device 20-30 devices), but rather loop/step/repeat through a variable. A bit more dynamic that way.

I like this idea - As far as I know however, there isnā€™t a way to replay events using Rule Machine.

it would be an interesting app to add to Hubitat though! I think it would require using the device ID rather than its name - that is the one variable that doesnā€™t change. (You can change your device name and description.)

1 Like

Yep, it worked quite nicely in my old system. Agree itā€™s better to use the device id (for reasons you mention)

1 Like

A follow up question:
Is there any performance/quality difference if I use 1 rule with a long IF - Then - else statement (will have 20-30 ELSE-ifs (depending of how many devices I connect) or if I instead create a rule per device (20-30 rules)?