Author Topic: luup.call_action code for EnergyMetering1 device ?  (Read 1437 times)

Offline Mai Pensato

  • Full Member
  • ***
  • Posts: 180
  • Karma: +3/-1
luup.call_action code for EnergyMetering1 device ?
« on: December 01, 2016, 03:12:42 pm »
I'm searching for the folllowing luup-code

Code: [Select]
luup.call_action("urn:upnp-org:serviceId:SwitchPower1", "SetTarget", {newTargetValue = 1}, 52)
for a EnergyMetering1 device to set the "Watts" value
something like:

Code: [Select]
luup.call_action("urn:micasaverde-com:serviceId:EnergyMetering1", "SetUsage", {newActualUsage = 40}, 52)
but that doesn't work..

Offline logread

  • Full Member
  • ***
  • Posts: 214
  • Karma: +7/-1
Re: luup.call_action code for EnergyMetering1 device ?
« Reply #1 on: December 01, 2016, 03:32:31 pm »
Anything that is not referenced at http://wiki.micasaverde.com/index.php/Luup_UPnP_Variables_and_Actions for standard devices cannot be expected to work... for energy meters the only standard action is ResetKWH...

But if you just want to display watts in the UI for a dummy device, then just a luup.variable_set will do
Vera Lite UI7, Fibaro FGS-221, FGS-212, FGSS-001, FGK-101, FGWPE/F-101, FGMS-001, Aeon HEM G2, GreenWave PowerNode 6,  Everspring ST-814, SE-812, Swiid SwiidInter.
Raspberry Pi2 Raspbian w/ openLuup. AltUI, SV Thermostat, Virtual Switch, Weather (openWeather), System Monitor (openSysMon), HomeWave.

Offline Mai Pensato

  • Full Member
  • ***
  • Posts: 180
  • Karma: +3/-1
Re: luup.call_action code for EnergyMetering1 device ?
« Reply #2 on: December 01, 2016, 03:51:54 pm »
Next to Vera I'm testing another HA system based on Raspberry Pi + Aeon-z stick and Domoticz. What I want to achieve is send the Watt value from a Power sensor within Domoticz to a virtual sensor in Vera. So I created a virtual sensor of the type EnergyMetering1.

What I managed to do is to change a virtual switch in Vera from Domoticz with the following code:

Code: [Select]
http://192.168.1.202:3480/data_request?id=lu_action&output_format=json&DeviceNum=301&serviceId=urn:upnp-org:serviceId:VSwitch1&action=SetTarget&newTargetValue=0
So now I'm looking for a similar method to do something similar with the Watt value.

So your proposed solution will not work I guess ...?

Offline reneboer

  • Hero Member
  • *****
  • Posts: 1140
  • Karma: +61/-30
Re: luup.call_action code for EnergyMetering1 device ?
« Reply #3 on: December 02, 2016, 04:17:44 am »
Hi,

I do not think you can set the Watts value like that. Normally the watts and KWH are values populated by the device and you can then read those variables. If you want to create a virtual PowerMeter device you will have the use the luup.variable_set function to put in the watt value.

I attached a simple example I use for my Solar panels. You first need to create the implementation file and upload it to your Vera. Then create a device (Apps, Develop Apps, Create Device) using the following:
Device type urn:schemas-micasaverde-com:device:PowerMeter:1
Upnp Device Filename D_PowerMeter1.xml
Upnp Implementation Filename I_ImplementationFileName.xml

After the reboot you can start debugging. the resulting device will look like any power meter device, even in the Vera and other phone apps.

Have fun, Rene
2xVeraLite, VeraEdge, openLuup, ALTUI, 20 switches, 10 dimmers, 20 sensors, 10 scene controllers, 1 Harmony Hub, many plug-ins. Not enough time.

Offline logread

  • Full Member
  • ***
  • Posts: 214
  • Karma: +7/-1
Re: luup.call_action code for EnergyMetering1 device ?
« Reply #4 on: December 02, 2016, 04:34:00 am »
@Mai Pensato, you may want to have a look at the Domoticz plugin I wrote... See http://forum.micasaverde.com/index.php/topic,39022.0.html
May be it will not fit the bill for you (BTW, it will NOT run on a real Vera), but the code posted on GitHub might help you.

Anyway, you could also try the following:

On the Vera (or openLuup system), manually create a device with the two config files below (no implementation file as we just want a dummy device):
device file = "D_PowerMeter1.xml"
device json = "D_PowerMeter1.json"

from the Domoticz system, you need then to call either or both of the following:

Code: [Select]
http://192.168.1.202:3480/data_request?id=variableset&DeviceNum=<your device id>&serviceId=urn:micasaverde-com:serviceId:EnergyMetering1&variable=Watts&Value=<the watts reading>

http://192.168.1.202:3480/data_request?id=variableset&DeviceNum=<your device id>&serviceId=urn:micasaverde-com:serviceId:EnergyMetering1&variable=KWH&Value=<the kWh reading>

Vera Lite UI7, Fibaro FGS-221, FGS-212, FGSS-001, FGK-101, FGWPE/F-101, FGMS-001, Aeon HEM G2, GreenWave PowerNode 6,  Everspring ST-814, SE-812, Swiid SwiidInter.
Raspberry Pi2 Raspbian w/ openLuup. AltUI, SV Thermostat, Virtual Switch, Weather (openWeather), System Monitor (openSysMon), HomeWave.

Offline Mai Pensato

  • Full Member
  • ***
  • Posts: 180
  • Karma: +3/-1
Re: luup.call_action code for EnergyMetering1 device ?
« Reply #5 on: December 02, 2016, 02:46:20 pm »

Anyway, you could also try the following:

On the Vera (or openLuup system), manually create a device with the two config files below (no implementation file as we just want a dummy device):
device file = "D_PowerMeter1.xml"
device json = "D_PowerMeter1.json"

from the Domoticz system, you need then to call either or both of the following:

Code: [Select]
http://192.168.1.202:3480/data_request?id=variableset&DeviceNum=<your device id>&serviceId=urn:micasaverde-com:serviceId:EnergyMetering1&variable=Watts&Value=<the watts reading>

http://192.168.1.202:3480/data_request?id=variableset&DeviceNum=<your device id>&serviceId=urn:micasaverde-com:serviceId:EnergyMetering1&variable=KWH&Value=<the kWh reading>

@logread:  thanks a lot !!!!  Now I've got it working.
There was a minor mistake in your code: "Variable" in stead of "variable" but I forgive you  :D :D :D
This is the correct code:

Code: [Select]
http://192.168.1.202:3480/data_request?id=variableset&DeviceNum=<your device id>&serviceId=urn:micasaverde-com:serviceId:EnergyMetering1&variable=Watts&Value=<the watts reading>

Where DeviceNum is the devicenumber of the dummy sensor in Vera (obviously).
Again thanks a lot !

Offline Mai Pensato

  • Full Member
  • ***
  • Posts: 180
  • Karma: +3/-1
Re: luup.call_action code for EnergyMetering1 device ?
« Reply #6 on: December 09, 2016, 02:57:23 pm »
@logread:
Do you have experience scripting in Domoticz ?
Thanks to you I know now how to send a value from Domoticz to a virtual powersensor in my Vera. Next step is to get the Watt value from a wallplug in Domoticz and sent it to the virtual sensor in Vera.

Read the value something like:

Code: [Select]
local Wattactual = tonumber(otherdevices_svalues["Greenwave1 Power"])
Where "Greenwave1 Powe"is the exact name of the device in Domoticz
But this doesn't work..

Offline logread

  • Full Member
  • ***
  • Posts: 214
  • Karma: +7/-1
Re: luup.call_action code for EnergyMetering1 device ?
« Reply #7 on: December 10, 2016, 02:15:29 am »
@logread:
Do you have experience scripting in Domoticz ?
Thanks to you I know now how to send a value from Domoticz to a virtual powersensor in my Vera. Next step is to get the Watt value from a wallplug in Domoticz and sent it to the virtual sensor in Vera.

Read the value something like:

Code: [Select]
local Wattactual = tonumber(otherdevices_svalues["Greenwave1 Power"])
Where "Greenwave1 Powe"is the exact name of the device in Domoticz
But this doesn't work..
This forum is probably not the best one to discuss Domoticz scripting, but I think you should rather try:
Code: [Select]
local Wattactual = tonumber(otherdevices["Greenwave1 Power"])
Vera Lite UI7, Fibaro FGS-221, FGS-212, FGSS-001, FGK-101, FGWPE/F-101, FGMS-001, Aeon HEM G2, GreenWave PowerNode 6,  Everspring ST-814, SE-812, Swiid SwiidInter.
Raspberry Pi2 Raspbian w/ openLuup. AltUI, SV Thermostat, Virtual Switch, Weather (openWeather), System Monitor (openSysMon), HomeWave.

Offline Mai Pensato

  • Full Member
  • ***
  • Posts: 180
  • Karma: +3/-1
Re: luup.call_action code for EnergyMetering1 device ?
« Reply #8 on: December 10, 2016, 06:42:58 am »
I know it's off topic but anyway thanks, I will try this.