Is it possible that a sensor displaying the temperature in degrees Celsius displays in a virtual sensor the temperature in degrees Fahrenheit?
This involves using the formula: F = 1.8 * C +32
Yes, certainly, no problem at all. All you need is to create another virtual temperature sensor and have a tiny bit of Lua code that runs in Lua Startup which watches and updates the new sensor every time the original changes. Just a few lines.
There are examples of similar things around the forum. I’ll try and post a link when I find a relevant one, but a search should help. It’s easy to recreate from scratch anyway.
Edit: the relevant Luup call to watch a variable is described here: http://wiki.micasaverde.com/index.php/Luup_Lua_extensions#function:_variable_watch
You can also do this with Reactor, but if you’re not already using Reactor for other things, it’s kind of a big hammer to hit a small nail with, and akbooer’s Lua-direct approach will surely be more direct.
Reactor method (assuming you’ve already created a dummy virtual sensor to receive the F temperature–you will need to know its device number as well):
- In the Expressions tab of a new ReactorSensor, add a new variable/expression called TempF, use this formula:
[tt] getstate( “SourceSensorName”, “urn:upnp-org:serviceId:TemperatureSensor1”, “CurrentTemperature” ) * 1.8 + 32[/tt]. Save. - Now go to the Conditions tab and create a new service type condition, select your new ReactorSensor itself from the list of devices, choose the TempF variable, and then the “changes” operator. Leave the remaining fields blank (so the condition will trigger on any change of value). Save.
- Now go to the Activities tab, and add a Run Lua activity in the Trip Actions with this code: [tt]luup.variable_set( “urn:upnp-org:serviceId:TemperatureSensor1”, “CurrentTemperature”, Reactor.variables.TempF, virtualSensorDeviceNumber )[/tt]
Again, if you’re not already using Reactor for other things, this is probably a good example of how you can do something with a certain tool, but it may not be the best way of getting it done. ![]()
I am a beginner with Reactor …
Thanks rigpapa.
It works great.