Physical thermostat turning on/off a device based on setpoint vs current temp

I have a small outbuilding in which I’ve installed an AC unit. I’ve connected that through an appliance module, and I have powered up and paired a thermostat in that building. I’d like to use Reactor to control the temperature of that building by comparing the current temperature in read by the thermostat to its cooling setpoint.

Currently, I’m just keeping the temperature of the building between two fixed setpoints: when CurrentTemperature goes above 82, I turn on the appliance module; when it falls below 75, I turn off the appliance module. I would like instead to have Reactor read TemperatureSetpoint1_Cool (whatever that is) and turn on the appliance module if CurrentTemperature is >1.5 degrees above… and off if Current temperature is >1.5 degrees below.

Any ideas? I haven’t used Expressions yet, but this may require I dive into that… thanks!

EDIT: I’ve been playing with Expressions, and my “Low” condition works to turn ON the AC unit… but the EXACT SAME expression on the high side is evaluated as a string, so instead of setting the variable with the value “78”, it sets the variable to “76.501.5”… that is, 76.5+1.5. This is infuriating. I’ve deleted the Expression and started over a few times. It makes no sense to me:

ShedLowTemp = getstate( "Thermostat, Shed", "urn:upnp-org:serviceId:TemperatureSetpoint1_Cool", "CurrentSetpoint" ) - 1.5 is a number, current value of 76.00.

ShedHighTemp = getstate( "Thermostat, Shed", "urn:upnp-org:serviceId:TemperatureSetpoint1_Cool", "CurrentSetpoint" ) + 1.5 is a string, current value of 75.001.5. WTF.

This works fine:

This will clearly never evaluate true:

If I type 75 into the ShedTempHigh field… it’s evaluated as a number. If I use the finder and get the device variable shown above (with or without adding 1.5), it’s a string. If I copy/paste, it’s a string. I haven’t the slightest idea why one of them is a number, and the other is a string.

Just wrap your getstate() calls in a tonumber() and you should be on your way: tonumber( getstate( ... ) )

The underlying expression parser uses “+” for string concatenation as well as addition. I took a peek, and it’s probably not making the best choice with respect to coercion of types there, so it’s something I can address for the future, but in the meanwhile, tonumber() is your friend.

It’s possible I have the syntax wrong… but

tonumber ( getstate( "Thermostat, Shed", "urn:upnp-org:serviceId:TemperatureSetpoint1_Cool", "CurrentSetpoint" ) )

throws an error. Invalid operator… even before adding + 1.5 to the end.

The lexer/parser is a little persnickety. Remove the space from between tonumber and the paren.

tonumber( getstate( "Thermostat, Shed", "urn:upnp-org:serviceId:TemperatureSetpoint1_Cool", "CurrentSetpoint" ) )

I have… same result. That was actually the first thing I tried.

Works great for me. Pasted it straight in. Removing the space was the only thing I needed to do.

Running it again, copy-pasting exactly what I posted above, I changed the device name to an AVT thermostat I have (so I don’t get a “device not found error”) and here is the result using the “test expression” button/icon.:

BTW, your screen shot shows the space is still in there.

Ah, wrong screen shot…

…but it works now. I deleted the variable name and started over. It now works with the + 1.5 tacked onto the end. Finally… thanks for that. Now I can operate it like a typical system and worry only about the temperature setpoint rather than having to cycle the AC manually.

1 Like

Just coming back to this one: it’s working flawlessly. It’s very responsive.

1 Like