Calculate the Amps of a group

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
janpeetoom
Posts: 12
Joined: Sunday 29 December 2019 12:07
Target OS: Linux
Domoticz version:
Contact:

Calculate the Amps of a group

Post by janpeetoom »

Hello to you all.

I'm having some difficulties on the following sctipt.

Code: Select all

return {

   on = { timer = { "every 1 minutes" }},     -- Change to your liking to 1,2,3,4,5,6,10,12,15 or 20  
   
   logging =
    {
        level = domoticz.LOG_DEBUG, -- Change to LOG_DEBUG to debug / Change to LOG_ERROR if script is running properly
        marker = scriptVar,
    },

   execute = function(dz, item)

       local StroomOpname = dz.devices(2524)
       local VermogenL1           = dz.devices(423)
       local VoltageL1            = dz.devices(422)

       local Predicted_Maxrange = ((VermogenL1 / VoltageL1))
       
       domoticz.log('--- Stroom opnamee------------------')
       domoticz.log(StroomOpname)
       domoticz.log('----------------------')

   end
}
I would like to calculate the amperage on group L1 but I get the following error message:
  • 2021-01-01 20:07:00.552 Status: dzVents: Info: ------ Start internal script: Script #1:, trigger: "every 1 minutes"
    2021-01-01 20:07:00.571 Status: dzVents: Debug: Processing device-adapter for Stroom L1: 1-phase Ampere device adapter
    2021-01-01 20:07:00.572 Status: dzVents: Debug: Processing device-adapter for Electriciteits verbruik L1: Electric usage device adapter
    2021-01-01 20:07:00.574 Status: dzVents: Debug: Processing device-adapter for Voltage: Voltage device adapter
    2021-01-01 20:07:00.574 Status: dzVents: Info: ------ Finished Script #1
    2021-01-01 20:07:00.574 Error: dzVents: Error: (3.0.2) An error occurred when calling event handler Script #1
    2021-01-01 20:07:00.574 Error: dzVents: Error: (3.0.2) ...domoticz/scripts/dzVents/generated_scripts/Script #1.lua:17: attempt to perform arithmetic on a table value (local 'VermogenL1')
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Calculate the Amps of a group

Post by waaren »

janpeetoom wrote: Friday 01 January 2021 20:08 attempt to perform arithmetic on a table value (local 'VermogenL1')
You try to divide one device object (a table) by another device object.

You probably want to divide the values of the actualWatt attribute of device with id 423 by the voltage attribute of device with id 422

something like

Code: Select all

return {

   on = { timer = { "every 1 minutes" }},     -- Change to your liking to 1,2,3,4,5,6,10,12,15 or 20  
   
   logging =
    {
        level = domoticz.LOG_DEBUG, -- Change to LOG_DEBUG to debug / Change to LOG_ERROR if script is running properly
        marker = 'Amperage',
    },

   execute = function(dz)

       local StroomOpname = dz.devices(2524)
       local VermogenL1 = dz.devices(423).actualWatt
       local VoltageL1 = dz.devices(422).voltage

       local Predicted_Maxrange = ((VermogenL1 / VoltageL1))
       
       dz.log('--- Stroom opname------------------')
       dz.log(StroomOpname)
       dz.log('----------------------')

   end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
janpeetoom
Posts: 12
Joined: Sunday 29 December 2019 12:07
Target OS: Linux
Domoticz version:
Contact:

Re: Calculate the Amps of a group

Post by janpeetoom »

Hey Waaren.

Thanks man for the quick response.
I have adapted your changes to my script and now get the following errors:[

Code: Select all

list] 2021-01-02 13:59:00.168 Status: dzVents: Info: Amperage: ------ Start internal script: Script #1:, trigger: "every 1 minutes"
2021-01-02 13:59:00.188 Status: dzVents: Debug: Amperage: Processing device-adapter for Stroom L1: 1-phase Ampere device adapter
2021-01-02 13:59:00.189 Status: dzVents: Debug: Amperage: Processing device-adapter for Electriciteits verbruik L1: Electric usage device adapter
2021-01-02 13:59:00.190 Status: dzVents: Debug: Amperage: Processing device-adapter for Voltage: Voltage device adapter
2021-01-02 13:59:00.190 Status: dzVents: Info: Amperage: --- Stroom opname------------------
2021-01-02 13:59:00.191 Status: dzVents: Debug: Amperage: OpenURL: url = http://127.0.0.1:8088/json.htm?type=command&param=udevice&idx=2524&nvalue=0&svalue=
2021-01-02 13:59:00.191 Status: dzVents: Debug: Amperage: OpenURL: method = GET
2021-01-02 13:59:00.191 Status: dzVents: Debug: Amperage: OpenURL: post data = nil
2021-01-02 13:59:00.191 Status: dzVents: Debug: Amperage: OpenURL: headers = nil
2021-01-02 13:59:00.191 Status: dzVents: Debug: Amperage: OpenURL: callback = nil
2021-01-02 13:59:00.192 Status: dzVents: Info: Amperage: ------ Finished Script #1
2021-01-02 13:59:00.193 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2021-01-02 13:59:00.191 Error: dzVents: Error: (3.0.2) Amperage: Method setKelvin is not available for device "Stroom L1" (deviceType=General, deviceSubType=Current). If you believe this is not correct, please report.
2021-01-02 13:59:00.191 Error: dzVents: Error: (3.0.2) Amperage: Method play is not available for device "Stroom L1" (deviceType=General, deviceSubType=Current). If you believe this is not correct, please report.
2021-01-02 13:59:00.191 Error: dzVents: Error: (3.0.2) Amperage: Method kodiPlayPlaylist is not available for device "Stroom L1" (deviceType=General, deviceSubType=Current). If you believe this is not correct, please report.
2021-01-02 13:59:00.191 Error: dzVents: Error: (3.0.2) Amperage: Method kodiPause is not available for device "Stroom L1" (deviceType=General, deviceSubType=Current). If you believe this is not correct, please report.
2021-01-02 13:59:00.191 Error: dzVents: Error: (3.0.2) Amperage: Method updateTempBaro is not available for device "Stroom L1" (deviceType=General, deviceSubType=Current). If you believe this is not correct, please report.
2021-01-02 13:59:00.191 Error: dzVents: Error: (3.0.2) Amperage: Method updateAlertSensor is not available for device "Stroom L1" (deviceType=General, deviceSubType=Current). If you believe this is not correct, please report.
2021-01-02 13:59:00.191 Error: dzVents: Error: (3.0.2) Amperage: Method updateDistance is not available for device "Stroom L1" (deviceType=General, deviceSubType=Current). If you believe this is not correct, please report.
2021-01-02 13:59:00.191 Error: dzVents: Error: (3.0.2) Amperage: Method onkyoEISCPCommand is not available for device "Stroom L1" (deviceType=General, deviceSubType=Current). If you believe this is not correct, please report.
2021-01-02 13:59:00.191 Error: dzVents: Error: (3.0.2) Amperage: No value given for 'withinXXX' command
2021-01-02 13:59:00.191 Error: dzVents: Error: (3.0.2) Amperage: An error occurred when calling event handler Script #1
2021-01-02 13:59:00.191 Error: dzVents: Error: (3.0.2) Amperage: /home/pi/domoticz/dzVents/runtime/TimedCommand.lua:195: attempt to perform arithmetic on a nil value (local 'value') [/list]
Quite strange to my opinion.

Any idea?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Calculate the Amps of a group

Post by waaren »

janpeetoom wrote: Saturday 02 January 2021 14:04 Any idea?
Yes. The line dz.log(StroomOpname) does cause this strange behaviour.

If you change that line to

StroomOpname.dump()

you will see all attributes and functions of that device in the domoticz log without getting the error messages.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest