Reading Power Consumption with Lua out of Fibaro
Moderator: leecollings
-
rgroothuis
- Posts: 347
- Joined: Friday 03 April 2015 17:09
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Reading Power Consumption with Lua out of Fibaro
Hi,
I'm trying to find the solution how I can read the Power Consumption that is reported from a Fibaro wall-plug into Domoticz using Lua scripting. I've done some searching on this forum but couldn't find the maybe simple answer. Also not on the WIKI. Any suggestions?
I want to check the power consumption and based on the level want to take some action.
Thanks, Cheers.
I'm trying to find the solution how I can read the Power Consumption that is reported from a Fibaro wall-plug into Domoticz using Lua scripting. I've done some searching on this forum but couldn't find the maybe simple answer. Also not on the WIKI. Any suggestions?
I want to check the power consumption and based on the level want to take some action.
Thanks, Cheers.
-
juankar
- Posts: 223
- Joined: Saturday 30 August 2014 20:20
- Target OS: Linux
- Domoticz version: 4.
- Location: Spain
- Contact:
Re: Reading Power Consumption with Lua out of Fibaro
Hi,
I don't know Fibaro, but I suppose it sends reports to Domoticz at a time interval or at value changes. If it's so you can create a script_device_<name fibaro module>.lua. In this script you can read the svalue of the device.
Example
Suppose your counter is named fibaroEnergy and it read usage (watts) and energy (kWh)
script_device_fibaroEnergy.lua
Print sentence is just for seeing the values reports by the device (you can see it in log)
Now you can compare or do anything based on energy or usage values. You can use tonumber(energy) to convert string energy into a number (for comparison or calculate).
Will this is useful for you?.
Bye
I don't know Fibaro, but I suppose it sends reports to Domoticz at a time interval or at value changes. If it's so you can create a script_device_<name fibaro module>.lua. In this script you can read the svalue of the device.
Example
Suppose your counter is named fibaroEnergy and it read usage (watts) and energy (kWh)
script_device_fibaroEnergy.lua
Code: Select all
commandArray = {}
local module = "fibaroEnergy"
local reading
local usage, energy
if (devicechanged[module]) then
reading = devicechanged[module]
_,_,usage, energy = string.find(reading, "(.+);(.+)")
print("Meter "..reading)
print("Usage: "..usage.."watts")
print("Energy: "..energy.."wh")
end
Now you can compare or do anything based on energy or usage values. You can use tonumber(energy) to convert string energy into a number (for comparison or calculate).
Will this is useful for you?.
Bye
-
rgroothuis
- Posts: 347
- Joined: Friday 03 April 2015 17:09
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Reading Power Consumption with Lua out of Fibaro
Thanks, that is useful info. I will give it a try. My main challenge is to get the values out of the Fibaro device.
Your line:
reading = devicechanged[module] _,_,usage, energy = string.find(reading, "(.+);(.+)")
Is this an example or the correct format/syntax?
My understanding is if I use: "devicechanged[module] " then I will get the On/Off status as this Fibaro device is also a power switch.
So the main question is how to get the Watts out of the Fibaro device.
Your line:
reading = devicechanged[module] _,_,usage, energy = string.find(reading, "(.+);(.+)")
Is this an example or the correct format/syntax?
My understanding is if I use: "devicechanged[module] " then I will get the On/Off status as this Fibaro device is also a power switch.
So the main question is how to get the Watts out of the Fibaro device.
-
juankar
- Posts: 223
- Joined: Saturday 30 August 2014 20:20
- Target OS: Linux
- Domoticz version: 4.
- Location: Spain
- Contact:
Re: Reading Power Consumption with Lua out of Fibaro
I wrote this script for an electricity counter. A swith will give ON/Off as status, but you spoke about an energy counder, did you?. So if you trigger the event from a switch then you can use
For a energy meter the svalue is a string like 25.0; 1230.000 or so. The first number before ";" is usage (watts) and the second is energy (wh). I repeat that I don't know fibaro, so I write this script based on switches I've used: Philio and Qubino switches. I think Fibaro works like them.
Bye
Code: Select all
reading = otherdevices_svalues["counter device_name"]
usage, energy = string.find(reading, "(.+);(.+)")
Bye
-
rgroothuis
- Posts: 347
- Joined: Friday 03 April 2015 17:09
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Reading Power Consumption with Lua out of Fibaro
Thanks for the useful tips. Based on the info provided I could make the following lines to read the power consumption out of a Fibaro wall-plug:
Code: Select all
BackGardenLampPowerInfo = otherdevices_svalues["BackGardenLampPower"]
start, stop = string.find(BackGardenLampPowerInfo, ";")
usage = string.sub(BackGardenLampPowerInfo, 1, start-1)
energy = string.sub(BackGardenLampPowerInfo, start+1, string.len(BackGardenLampPowerInfo))
print ('Back Garden Lamp Power consumption: ' .. usage .. ' Watt, ' .. energy .. ' wh.')
-
dannybloe
- Posts: 1355
- Joined: Friday 29 August 2014 11:26
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Ermelo
- Contact:
Re: Reading Power Consumption with Lua out of Fibaro
Check out dzVents. It has all the methods to get to this information in an easy (and more, much more).
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
-
rgroothuis
- Posts: 347
- Joined: Friday 03 April 2015 17:09
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Reading Power Consumption with Lua out of Fibaro
I'm still having problems with reading out the power consumption from my Fibaro wall-plug. I'm trying to get my head around it but no luck. Any support would be appreciated.
Domoticz is reading out the power consumption from the Fibaro wall-plug, see screenshot. 0.7 Watt at the moment when the picture was taken.
But now I'm trying to get this value within my Lua script and I only get 0 Watt. Really strange.
My Lua script snapshot:
And the Domoticz log:
Any idea why in Lua I get 0.000 and not the 0.7 Watt as in the Domoicz GUI?
Domoticz is reading out the power consumption from the Fibaro wall-plug, see screenshot. 0.7 Watt at the moment when the picture was taken.
But now I'm trying to get this value within my Lua script and I only get 0 Watt. Really strange.
My Lua script snapshot:
Code: Select all
print('------ ** Test1: ' .. otherdevices['BackGardenLampPower'] .. '.')
print('------ ** Test2: ' .. otherdevices_svalues['BackGardenLampPower'] .. '.')Code: Select all
2016-09-22 22:58:00.060 LUA: ------ ** Test1: .
2016-09-22 22:58:00.060 LUA: ------ ** Test2: 0.000;45240.000.-
ben53252642
- Posts: 543
- Joined: Saturday 02 July 2016 5:17
- Target OS: Linux
- Domoticz version: Beta
- Contact:
Re: Reading Power Consumption with Lua out of Fibaro
Thanks for posting this, I've modified my washing machine script to get watts from a kWh sensor instead of the dedicated watts sensor.juankar wrote: Wednesday 08 June 2016 19:02 Hi,
I don't know Fibaro, but I suppose it sends reports to Domoticz at a time interval or at value changes. If it's so you can create a script_device_<name fibaro module>.lua. In this script you can read the svalue of the device.
Example
Suppose your counter is named fibaroEnergy and it read usage (watts) and energy (kWh)
script_device_fibaroEnergy.luaPrint sentence is just for seeing the values reports by the device (you can see it in log)Code: Select all
commandArray = {} local module = "fibaroEnergy" local reading local usage, energy if (devicechanged[module]) then reading = devicechanged[module] _,_,usage, energy = string.find(reading, "(.+);(.+)") print("Meter "..reading) print("Usage: "..usage.."watts") print("Energy: "..energy.."wh") end
Now you can compare or do anything based on energy or usage values. You can use tonumber(energy) to convert string energy into a number (for comparison or calculate).
Will this is useful for you?.
Bye
Code: Select all
commandArray = {}
local module = "Washing Machine / Dryer kWh"
local reading
local wattvalue
if (devicechanged[module]) then
reading = devicechanged[module]
_,_,wattvalue = string.find(reading, "(.+);(.+)")
wattvalue = tonumber(wattvalue)
if (uservariables["WashingMachineState"] == 'notinuse' and wattvalue >= 10 ) then
commandArray['Variable:WashingMachineState'] = 'inuse'
end
if (uservariables["WashingMachineState"] == 'inuse' and wattvalue <= 1 ) then
commandArray['Variable:WashingMachineState'] = 'notinuse'
commandArray['SendNotification']='Domoticz#The washing machine has finished.'
end
end
return commandArray
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
Who is online
Users browsing this forum: No registered users and 0 guests