'Average' Virtual Sensor/Switch Needed

Anyone up for creating a plugin (or code) that would create a virtual sensor (or switch) made up of the average values of a specific set of devices? Examples could be to give the average value of a number of temp sensors, light sensors, or even the average units that are on or off - I don’t think it would make a difference what you are measuring just need to define which devices you want to include. Once set up this “device’s” value can be used as a trigger for all sorts of things.

Anyone have time to do this? I wish I knew how and it seems fairly simple.

Thanks,

M

There is probably an easier way to do this but this works.

Create a Virtual Device. I created a Virtual Temperature because it will dispaly the Variable.

Go to Mios Developer. Create Device. Use “D_TemperatureSensor1” for the UpnpDevFilename and “S_TemperatureSensor1” for the UpnpImplFilename

Create a scene.
Add a timer to the scene that runs as often as you like. I set mine to every 2 minutes to test.
Add the following code to the LUUP in the scene:

local temp1 = luup.variable_get(“urn:upnp-org:serviceId:TemperatureSensor1”,“CurrentTemperature”,116)

local temp2 = luup.variable_get(“urn:upnp-org:serviceId:TemperatureSensor1”,“CurrentTemperature”,25)

local temp3 = luup.variable_get(“urn:upnp-org:serviceId:TemperatureSensor1”,“CurrentTemperature”,47)

local total = temp1 + temp2 + temp3

local avg = total / 3

luup.variable_set(“urn:upnp-org:serviceId:TemperatureSensor1”,“CurrentTemperature”,avg,150)

I have three temps that are device numbers 116, 25, 47. My new Virtual Temp is device 150.

The virtual temp I named average and now it display the average for the three temps.

Nice little write up. This can be useful.

  • Garrett

[quote=“NovaIceman, post:2, topic:171528”]There is probably an easier way to do this but this works.

Create a Virtual Device. I created a Virtual Temperature because it will dispaly the Variable.

Go to Mios Developer. Create Device. Use “D_TemperatureSensor1” for the UpnpDevFilename and “S_TemperatureSensor1” for the UpnpImplFilename

Create a scene…[/quote]

Awesome! Works perfectly - I added “urn:schemas-micasaverde-com:device:TemperatureSensor:1” to “device type” so it shows up as a sensor.

I thought the device type was automatically added from the device file. Sorry

Maybe it does, could be a lag - I’ve seen that before.

Seems to come up as a generic_device

S_TemperatureSensor1 is a service file and shouldn’t be used as an implementation file. The temperature sensor device doesn’t require any implementation file, because no actions are defined for it.

When creating a device it’s not necessary to specify the device type, because it is read from the device file.

After creating a device a reload of Luup is required. Otherwise the device will come up as a generic device.

I cannot seem to get this to work to trigger a scene - When I set the scene to trigger based on the temp of another thermostat it fires the scene just fine. When I use this virtual device it just doesn’t seem to work - I set the trigger as “temp goes below x”

any ideas?

I have read in a few other threads in the past day or two that people have issues with the trigger “temp goes below”. It sounds like you are experiencing the same issues as they are.

  • Garrett

same for “temp goes above” - neither seem to work

[quote=“garrettwp, post:10, topic:171528”]I have read in a few other threads in the past day or two that people have issues with the trigger “temp goes below”. It sounds like you are experiencing the same issues as they are.

  • Garrett[/quote]

it is so odd, The Google weather virtual sensor (which seems to be of the same type) triggers scenes and notifications just fine. Any idea why this Avg Temp sensor won’t trigger anything? I even tried changing the type to thermostat and it did nothing.

@resq93
Is your variable defined in the service file? Variables that are not in the service file can’t be used to trigger scenes.

I’m not that savvy - I simply followed the instructions given by NovaIceman - can you clarify what it is that i need to do to make this work?

Thanks,

M

Actually the CurrentTemperature variable is used, which is declared in the service file, so this is not the problem. I’ll have to investigate.

When I use the value generated by this sensor in a LUUP code like below it does work properly, it just doesn’t work as a standalone trigger

avg = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 50)

Thanks,

m

Any result of this investigation yet?

I couldn’t reproduce this. I tired both Temperature goes below and Temperature goes above and they triggered both notifications and scenes. Can you post here the full code that you’re using?

By the way, what firmware version do you have?

Firmware is 1.5.346

I am not using any code - i just created a scene that should trigger based on “temp goes above” - temp went above and nothing happens nor do I get a notification . There are no luup codes or conditions attached.

Can you enable Tech Support on your Vera so I can investigate?