Smanar / Domoticz-deCONZ

deCONZ plugin for Domoticz (Zigbee application)
GNU General Public License v3.0
36 stars 27 forks source link

Combine 2 domoticz innr devices #52

Closed dennisb1 closed 3 years ago

dennisb1 commented 4 years ago

I have a powerplug the SP120 from innr and in domoticz i have a sensor for watt and a sensor for kwh.

How can i combine these 2 into one sensor? Has anyone has a script like the temperature sensor?

Smanar commented 4 years ago

But you still have the problem with cpu usage when you use script ?

Do you prefer with lua or dzevent ?

dennisb1 commented 4 years ago

What ever is easier, im not a programmer so i hope someone has a script in stock and can even put it on the wiki for everyone to use. I am still using dzevent because it is working, that i have a higher CPU usage well, it is what it is. I am reinstalling my raspberry in a few days so maybe this will even fix it.

Smanar commented 4 years ago

You have ask in Domoticz forum to see if it's something normal ? not for me.

I will try to make one in dzevent else it will be in LUA.

Smanar commented 4 years ago

Ok so I have finally make it working (almost) The code

Power_Sensor = 'deCONZ - Cable outlet'
Energy_Sensor = 'testcount'
PE_Sensor = 'cumul'

return {
    active = true,
    on = {
          devices = {
             Power_Sensor
          }
    },

    execute = function(domoticz,sensor)

        local function logWrite(str)
            domoticz.log(tostring(str))
        end

        function deviceType(device)
            if device ~= nil then
                if domoticz.devices(device).deviceType:upper() == "GENERAL" then
                    return domoticz.devices(device).deviceSubType
                else
                    return domoticz.devices(device).deviceType
                end
            else
                return nil
            end
        end

        local function UpdateSensor()
            P = domoticz.devices(Power_Sensor).actualWatt
            logWrite("Power : "..P)

            if (domoticz.devices(Energy_Sensor) ~= nil) and (deviceType(Energy_Sensor) == 'RFXMeter' ) then
                if domoticz.devices(Energy_Sensor).counter ~= nil then
                    E = domoticz.devices(Energy_Sensor).counter
                    logWrite("Energy : "..E)
                end

            end

            if P ~= nil and E ~= nil and domoticz.devices(PE_Sensor) then
                domoticz.devices(PE_Sensor).updateElectricity(P , E)
                logWrite("update device "..domoticz.devices(PE_Sensor).name)
           end
        end

        UpdateSensor()

    end
}
Smanar commented 4 years ago

BTW, I m not sure this kind of device is possible

Electricity (instant and counter) IDX = id of your device (This number can be found in the devices tab in the column "IDX") POWER = current power ENERGY = cumulative energy in Watt-hours (Wh) This is an incrementing counter. (if you choose as type "Energy read : Computed", this is just a "dummy" counter, not updatable because it's the result of DomoticZ calculs from POWER)

And your device send already a cumulative value, we need to use it as it, and this widget add the value to the previous, so the result is bad.

dennisb1 commented 3 years ago

Sorry for my late reply, some personal issues. The script works fine if i use it only once.

When i enable it for the "Koelkast" and "Vriezer" at the same time something strange is happening. The Koelkast is updating the device Vriezer and the Vriezer script is updating also the Vriezer as supposed to. When i disable the Vriezer and only have the Koelkast enabled then its updating fine the Koelkast device...

What am i missing? See log below;

2020-10-15 20:42:30.088 Status: dzVents: Info: Handling events for: "Koelkast-Watt", value: "3" 2020-10-15 20:42:30.088 Status: dzVents: Info: ------ Start internal script: Koelkast: Device: "Koelkast-Watt (deCONZ)", Index: 174 2020-10-15 20:42:30.088 Status: dzVents: Info: Power : 31 2020-10-15 20:42:30.089 Status: dzVents: Info: Energy : 55.94 2020-10-15 20:42:30.089 Status: dzVents: Info: update device Vriezer 2020-10-15 20:42:30.089 Status: dzVents: Info: ------ Finished Koelkast 2020-10-15 20:42:30.089 Status: EventSystem: Script event triggered: /home/dennis/domoticz/dzVents/runtime/dzVents.lua 2020-10-15 20:42:31.379 Status: dzVents: Info: Handling events for: "Vriezer-Watt", value: "34" 2020-10-15 20:42:31.379 Status: dzVents: Info: ------ Start internal script: Vriezer: Device: "Vriezer-Watt (deCONZ)", Index: 143 2020-10-15 20:42:31.379 Status: dzVents: Info: Power : 34 2020-10-15 20:42:31.380 Status: dzVents: Info: Energy : 55.94 2020-10-15 20:42:31.380 Status: dzVents: Info: update device Vriezer 2020-10-15 20:42:31.380 Status: dzVents: Info: ------ Finished Vriezer 2020-10-15 20:42:31.380 Status: EventSystem: Script event triggered: /home/dennis/domoticz/dzVents/runtime/dzVents.lua

Vriezer: Power_Sensor = 'Vriezer-Watt' Energy_Sensor = 'Vriezer-kWh' PE_Sensor = 'Vriezer'

Koelkast: Power_Sensor = 'Koelkast-Watt' Energy_Sensor = 'Koelkast-kWh' PE_Sensor = 'Koelkast'

dennisb1 commented 3 years ago

Found a work around! For the Koelkast in this example i have modifed the script:

Power_Sensor1 = 'Koelkast-Watt' Energy_Sensor1 = 'Koelkast-kWh' PE_Sensor1 = 'Koelkast'

Also ofcourse everywhere i have put a 1 in the values.

You really should put this in your wiki this script like the temp one!

Smanar commented 3 years ago

Ha yep, I have made this script for only 1 sensor, It can't work as it for 2 sensors. The second one overwrite the first one.