Global Variables - use a device


#1

Is it possible to create a Global Variable that changes its output piston to piston based on a device? For example, let’s say 1) I want to read out a thermostat’s heat set point, 2) I have 2 thermostats in separate pistons, 3) I have a Global Variable @ThermoHeat. I was hoping to set the value to [$device : heatsetpoint] then simply call @ThermoHeat in the piston (I KNOW you can simply call the device in the piston - this is only an example - pretend I need to do this dozens of times on multiple attributes).

With the above example, all I get as output is the literal ‘$device : heatsetpoint’ rather than an actual setpoint. Is there a magic way to write that that I have overlooked to make it work?

I have tried as expression, as value; with { or ( or [; as $device, @device; I have even set the value into a local variable then simply tried to get the global variable to call that local - all to no avail.

Feels like this is ‘a no’, but I figured I’d ask!

To take it a step further, it would be cool if the global variables can do things when they get called. IE today I find that they can be a value (blue). But I’d like them to expressions that change based on the rest of the piston’s attributes.

@TempBasedSelection: ThermoTemp == 40 ? ‘blue’ : (ThermoTemp == 50 ? ‘green’ : (ThermoTemp == 60 ? ‘Red’ : ‘Yellow’)))
*please understand this is an example only!

Thanks for reviewing.


#2

Global variables cannot contain such things.

You would need a master piston to set the global variable on each thermostat event… then the other pistons can just look up the global variable.

Master piston:

On events from thermostat’s Heating Setpoint
set @thermoHeat to [$device:heatingSetpoint]

On events from thermostat’s temperature
Set @TempBasedSelection to ([$device:Temperature] == 40 ? ‘blue’ : ([$device:Temperature] == 50 ? ‘green’ : ([$device:Temperature] == 60 ? ‘Red’ : ‘Yellow’)))

On events from thermostat’s X
set @thermoX to [$device:X ]

Etc etc…


#3

Thanks @Robin, I appreciate the reply.

That is too bad. Your solution COULD work, but let’s shift this to light luminance level. You could imagine you could easily have dozens of lights (more likely than dozens of thermos!). This would require individual global for each light - at which point, you might as well have the logic in the piston. The hope of course was to have the global scratch pad, that ‘at that moment/at that pistons state’ it would gather a value to be spit back out in that piston.

In effect I can also do this with local variables, I was just trying to make it complicated! :slight_smile: Thanks again. Cheers!


#4

Pistons can pass pass arguments between themselves… so piston 1 could call piston 2, piston 2 can run the checks and return a value back to piston 1


#5

You could also array all the lux values into a single global variable.

Define
deviceList: X, Y, Z

On events from deviceList’s Lux
DO
With $currentEventDevice
Set @DeviceListGlobal[$index] to $currentEventDevice
Set @DeviceValueGlobal[$index] to [$currentEventDevice:Lux]


#6

Hello!

Do you know if it’s possible to subscribe to a global variable set by a master piston which sets the global variable to the current active room?

This is my piston which was suppose to subscribe to the current device set in the global variable, but when I save/start the shown piston, the piston only subscribes to the currently set device and does not respect if the device have switched based on the contents of the variable since it was started.