Script for P1 not working good
Posted: Monday 12 December 2022 22:59
Dear forum members,
Can anyone help me to solve the below problem
I found the script below on this forum
In this script, the data of P1 is divided into 6 pieces.
I only need the 6th number then.
The 6th number is the feed back I want to use with a dummy.
Unfortunately the script gives an error that I can't get out of.
The error is at the bottom of the script.
I turned off everything except what I want to use.
If this script works, I want to use it fully.
json of the P1
Can anyone help me to solve the below problem
I found the script below on this forum
In this script, the data of P1 is divided into 6 pieces.
I only need the 6th number then.
The 6th number is the feed back I want to use with a dummy.
Unfortunately the script gives an error that I can't get out of.
The error is at the bottom of the script.
I turned off everything except what I want to use.
If this script works, I want to use it fully.
Code: Select all
-- dzVents script to Parse P1 Smart Meter Electricity value into separate Meter Readings.
local fetchIntervalMins = 1 -- (Integer) Minutes frequence of this script execution 1 = every minute, 10 = every 10 minutes, etc ) must be one of (1,2,3,4,5,6,10,12,15,20,30)
local ScriptVersion = '0.1.8'
return {
on = {
timer = { 'every ' .. fetchIntervalMins .. ' Minutes' }
},
logging = {
level = domoticz.LOG_DEBUG, -- Uncomment this line to override the dzVents global logging setting
marker = 'SME '.. ScriptVersion
},
execute = function(dz, item)
-- The following need updated for your environment get the 'Idx' or 'Name' of the Device tab.
local P1data = 50 -- Electra, P1 Smart Meter device
--local idxu1 = 43 -- Meter Usage low, Virtual device, counter incremental
--local idxu2 = 44 -- Meter Usage High, Virtual device, counter incremental
--local idxr1 = 45 -- Meter Return Low, Virtual device, counter incremental
--local idxr2 = 46 -- Meter Return High, Virtual device, counter incremental
--local idxcons = 103 -- Meter Actual Usage, Virtual device, counter incremental
local idxprod = 947 -- Meter Actual Production, Virtual device, counter incremental
-- Get values from device P1Data of the Smart Meter
local SMdata = dz.devices(P1data)
local function updateCounter(idx,value)
dz.devices(idx).updateCounter(value)
dz.log("Set " .. dz.devices(idx).name .. " to: ",dz.LOG_DEBUG)
end
-- Update the device and Debug meassages with the accessory values from table SMdata
updateCounter(idxu1,SMdata.usage1)
--updateCounter(idxu2,SMdata.usage2)
--updateCounter(idxr1,SMdata.return1)
--updateCounter(idxr2,SMdata.return2)
--updateCounter(idxcons,SMdata.usage)
updateCounter(idxprod,SMdata.usageDelivered)
end
}
--[[
2022-12-08 22:26:00.261 Error: dzVents: Error: (3.1.8) SME 0.1.8: An error occurred when calling event handler P1 opgedeeld test 3
2022-12-08 22:26:00.261 Error: dzVents: Error: (3.1.8) SME 0.1.8: ...cripts/dzVents/generated_scripts/P1 opgedeeld test 3.lua:33: attempt to call a nil value (field 'updateCounter')
]]--
Code: Select all
{
"ActTime" : 1670418525,
"AstrTwilightEnd" : "18:35",
"AstrTwilightStart" : "06:31",
"CivTwilightEnd" : "17:11",
"CivTwilightStart" : "07:55",
"DayLength" : "07:57",
"NautTwilightEnd" : "17:55",
"NautTwilightStart" : "07:11",
"ServerTime" : "2022-12-07 14:08:45",
"SunAtSouth" : "12:33",
"Sunrise" : "08:35",
"Sunset" : "16:31",
"app_version" : "2022.2",
"result" :
[
{
"AddjMulti" : 1.0,
"AddjMulti2" : 1.0,
"AddjValue" : 0.0,
"AddjValue2" : 0.0,
"BatteryLevel" : 255,
"Counter" : "14162.493",
"CounterDeliv" : "1122.482",
"CounterDelivToday" : "0.594 kWh",
"CounterToday" : "2.094 kWh",
"CustomImage" : 0,
"Data" : "6815859;7346634;338996;783486;0;180",
"Description" : "",
"Favorite" : 1,
"HardwareDisabled" : false,
"HardwareID" : 3,
"HardwareName" : "Energie meters",
"HardwareType" : "P1 Smart Meter USB",
"HardwareTypeVal" : 4,
"HaveTimeout" : false,
"ID" : "0001",
"LastUpdate" : "2022-12-07 14:03:37",
"Name" : "Elektriciteitmeter",
"Notifications" : "false",
"PlanID" : "14",
"PlanIDs" :
[
14
],
"Protected" : false,
"ShowNotifications" : true,
"SignalLevel" : "-",
"SubType" : "Energy",
"SwitchTypeVal" : 0,
"Timers" : "false",
"Type" : "P1 Smart Meter",
"TypeImg" : "counter",
"Unit" : 1,
"Usage" : "0 Watt",
"UsageDeliv" : "180 Watt", (6e number from "Data")
"Used" : 1,
"XOffset" : "0",
"YOffset" : "0",
"idx" : "50"
}
],
"status" : "OK",
"title" : "Devices"
}