Using P1-device form Dutch Homewizard

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
florisjan
Posts: 2
Joined: Wednesday 23 December 2020 0:46
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Using P1-device form Dutch Homewizard

Post by florisjan »

Hi,

I try to connect the P1-device (that is connected to my LAN via WiFi) to my Domoticz-application on my NAS (Synology).

I use the type P1-meter with LANinterface combined with remote address: localIP//api/v1/data:20000

In the logs I find this errors:
2020-12-23 00:47:24.298 Error: Restarting: Homewizard
2020-12-23 00:47:29.641 Error: SolarEdgeAPI: Error getting http data!
2020-12-23 00:47:38.493 Error: P1MeterTCP: Host not found (authoritative)
2020-12-23 00:48:08.549 Error: P1MeterTCP: Host not found (authoritative)
2020-12-23 00:48:33.935 Error: Homewizard hardware (13) nothing received for more than 1 Minute!....
2020-12-23 00:48:34.946 Error: Restarting: Homewizard
2020-12-23 00:48:38.580 Error: P1MeterTCP: Host not found (authoritative)
2020-12-23 00:48:40.148 Error: SolarEdgeAPI: Error getting http data!
2020-12-23 00:49:08.613 Error: P1MeterTCP: Host not found (authoritative)
2020-12-23 00:49:43.653 Error: P1MeterTCP: Host not found (authoritative)
2020-12-23 00:49:44.510 Error: Homewizard hardware (13) nothing received for more than 1 Minute!....
2020-12-23 00:49:45.518 Error: Restarting: Homewizard

Is it posible to connect this device?
P1-meter_Homewizard.jpg
P1-meter_Homewizard.jpg (118.57 KiB) Viewed 7132 times
Regards,
Florisjan
smaus
Posts: 84
Joined: Sunday 18 February 2018 9:32
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Using P1-device form Dutch Homewizard

Post by smaus »

I will follow this
SanderRoelofs
Posts: 17
Joined: Thursday 11 March 2021 10:03
Target OS: Windows
Domoticz version:
Contact:

Re: Using P1-device form Dutch Homewizard

Post by SanderRoelofs »

Hi,

You need to use the HTTP/HTTPS poller.

Method = GET
ContentType = application/JSON
url = http://{p1 ipadres}/api/v1/data
Command = p1.lua
Interval = {value in seconds}

Two virtual sensors (Gas and Smart Energy Meter)

and lua script saved in scripts folder

p1.lua script:
------ BEGIN ------
-- Read API values
s = request['content'];

--
-- Gasmeter
--
local idGas = 101
local a = domoticz_applyJsonPath(s,'.total_gas_m3')
domoticz_updateDevice(idGas,'',a*1000)

--
-- Energiemeter
--

-- Dal import value
local b = domoticz_applyJsonPath(s,'.total_power_import_t1_kwh')
-- Piek import value
local c = domoticz_applyJsonPath(s,'.total_power_import_t2_kwh')
-- Dal return value
local d = domoticz_applyJsonPath(s,'.total_power_export_t1_kwh')
-- Piek return value
local e = domoticz_applyJsonPath(s,'.total_power_export_t2_kwh')
-- Active Watt Usage
local f = domoticz_applyJsonPath(s,'.active_power_w')
local g = domoticz_applyJsonPath(s,'active_power_l1_w')
local h = domoticz_applyJsonPath(s,'active_power_l2_w')
local i = domoticz_applyJsonPath(s,'active_power_l3_w')
--

local idEnergy = 100
domoticz_updateDevice(idEnergy,'',b*1000 ..";"..c*1000 ..";"..d..";"..e..";"..f..";"..'0')
------ END ------

It's a simple script to read the values (it is not perfect because I'm not a script person but it works

lookup your idx numbers for the sensors and replace in script

local idGas = 101
local idEnergy = 100
User avatar
waltervl
Posts: 5714
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Using P1-device form Dutch Homewizard

Post by waltervl »

General HTTP/HTTPS Poller instructions here: https://www.domoticz.com/wiki/HTTP/HTTPS_poller
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
SanderRoelofs
Posts: 17
Joined: Thursday 11 March 2021 10:03
Target OS: Windows
Domoticz version:
Contact:

Re: Using P1-device form Dutch Homewizard

Post by SanderRoelofs »

waltervl wrote: Thursday 11 March 2021 11:46 General HTTP/HTTPS Poller instructions here: https://www.domoticz.com/wiki/HTTP/HTTPS_poller
Thanks for your update. SO use general information about General HTTP/HTTPS Poller instruction and use mine p1.lua script for reading the values.
rboerdijk
Posts: 7
Joined: Friday 20 May 2016 22:53
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Using P1-device form Dutch Homewizard

Post by rboerdijk »

For the newbies (like me), script needs to be under in the folder /scripts/lua_parsers and you want to use the "Idx" value as shown under devices (not "ID") ;)

Also, the values look a bit mess up, is this expected?
docker-p1-energy.png
docker-p1-energy.png (40.69 KiB) Viewed 6542 times
brax
Posts: 2
Joined: Sunday 26 September 2021 0:55
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Using P1-device form Dutch Homewizard

Post by brax »

rboerdijk wrote: Sunday 05 September 2021 14:28 For the newbies (like me), script needs to be under in the folder /scripts/lua_parsers and you want to use the "Idx" value as shown under devices (not "ID") ;)

Also, the values look a bit mess up, is this expected?
docker-p1-energy.png
Hi
i got the same issue with negative values coming from the P1 meter
I found this solution...
https://github.com/domoticz/domoticz/issues/4521
brax
Posts: 2
Joined: Sunday 26 September 2021 0:55
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Using P1-device form Dutch Homewizard

Post by brax »

brax wrote: Sunday 26 September 2021 0:56
rboerdijk wrote: Sunday 05 September 2021 14:28 For the newbies (like me), script needs to be under in the folder /scripts/lua_parsers and you want to use the "Idx" value as shown under devices (not "ID") ;)

Also, the values look a bit mess up, is this expected?
docker-p1-energy.png
Hi
i got the same issue with negative values coming from the P1 meter
I found this solution...
https://github.com/domoticz/domoticz/issues/4521
Hi
I found the solution in the Lua script (a little bit trial & error)
don't forget to change the idx numbers

------ BEGIN ------
-- Read API values
s = request['content'];

--
-- Gasmeter
--
local idGas = 5
local a = domoticz_applyJsonPath(s,'.total_gas_m3')
domoticz_updateDevice(idGas,'',a*1000)

--
-- Energiemeter
--

-- Dal import value
local b = domoticz_applyJsonPath(s,'.total_power_import_t1_kwh')
-- Piek import value
local c = domoticz_applyJsonPath(s,'.total_power_import_t2_kwh')
-- Dal return value
local d = domoticz_applyJsonPath(s,'.total_power_export_t1_kwh')
-- Piek return value
local e = domoticz_applyJsonPath(s,'.total_power_export_t2_kwh')
-- Active Watt Usage
local f = domoticz_applyJsonPath(s,'.active_power_w')
local g = math.abs(domoticz_applyJsonPath(s,'.active_power_w'))
if f<0 then f = 0 elseif f>0 then g = 0 end
local h = domoticz_applyJsonPath(s,'active_power_l1_w')
local i = domoticz_applyJsonPath(s,'active_power_l2_w')
local j = domoticz_applyJsonPath(s,'active_power_l3_w')

--

local idEnergy = 4
domoticz_updateDevice(idEnergy,'',b*1000 ..";"..c*1000 ..";"..d*1000 ..";"..e*1000 ..";"..f..";"..g)
------ END ------

works great for my belgian digital meter with the homewizard P1-meter
pauldune
Posts: 1
Joined: Wednesday 04 November 2020 8:42
Target OS: Windows
Domoticz version:
Contact:

Re: Using P1-device form Dutch Homewizard

Post by pauldune »

The solution from Brax works perfectly! With the LUA script provided, and the right Idx (you'll need the Idx and not the ID!) and the http/https poller, I get now perfect results.
Even better, I used this method to make a sensor for the Shelly EM1 too, works perfect, no node red or mqtt necessary.
Thanks Brax!
Pheinstra
Posts: 1
Joined: Wednesday 28 September 2022 20:38
Target OS: -
Domoticz version:
Contact:

Re: Using P1-device form Dutch Homewizard

Post by Pheinstra »

I know it has been quite some time since this post was active.
I have just purchased a Homewizard P1 meter and used this method and it works like a charm! So thanks for that.

I was wondering if it is also possible to get readings on the seperate fases.......does anyone know how to do that properly? I have managed to get readings on the current usage for the different fases by changing the "f" (in the "domoticz_updateDevice" part) in the letters of the fases (so, 1 for G, 1 for H and 1 for I). but the graphs in the log of the device still show the total usage of the 3 fases combined...... as i sometimes have weird peaks in the total amount i want to find out on which fase they occur.
I am quite a noob (or maybe even a total noob :) ) on scripting........

Thanks in advance for your help!!

Regards,

Koen
guidohuijnen
Posts: 1
Joined: Monday 19 September 2016 18:44
Target OS: -
Domoticz version:
Contact:

Re: Using P1-device form Dutch Homewizard

Post by guidohuijnen »

I'm a complete noob with Lua...

Can someone help why I get this error:

input:3: attempt to index a nil value (global 'request')

Thnx & regards,
Guido
willemd
Posts: 631
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: Using P1-device form Dutch Homewizard

Post by willemd »

guidohuijnen wrote: Saturday 01 October 2022 18:32 I'm a complete noob with Lua...

Can someone help why I get this error:

input:3: attempt to index a nil value (global 'request')

Thnx & regards,
Guido
You need to add some more info before anyone can help.
What have you done/configured? When do you get this error? What is the code/script used that produces this error?
SanderRoelofs
Posts: 17
Joined: Thursday 11 March 2021 10:03
Target OS: Windows
Domoticz version:
Contact:

Re: Using P1-device form Dutch Homewizard

Post by SanderRoelofs »

Hi,

Little late response but I have readings for 3 phases and extra.
since my first script I've now solar panels, 3 phase system and waiting for water meter. So I have updated my first script several times now.

Code: Select all

-- Read API values
s = request['content'];

--
-- Gasmeter
--
local idGas = {idx value}
local a = domoticz_applyJsonPath(s,'.total_gas_m3')
domoticz_updateDevice(idGas,'',a*1000)

--
-- Energiemeter
--

-- Dal import value
local b = domoticz_applyJsonPath(s,'.total_power_import_t1_kwh')
-- Piek import value
local c = domoticz_applyJsonPath(s,'.total_power_import_t2_kwh')
-- Dal return value
local d = domoticz_applyJsonPath(s,'.total_power_export_t1_kwh')
-- Piek return value
local e = domoticz_applyJsonPath(s,'.total_power_export_t2_kwh')
-- Active Watt Usage
local w = domoticz_applyJsonPath(s,'.active_power_w')
if w > 0 then f = w g = 0 else f = 0 g = w end
local L1 = domoticz_applyJsonPath(s,'active_power_l1_w')
local L2 = domoticz_applyJsonPath(s,'active_power_l2_w')
local L3 = domoticz_applyJsonPath(s,'active_power_l3_w')
--

local idEnergy = {idx value}
domoticz_updateDevice(idEnergy,'',b*1000 ..";"..c*1000 ..";"..d*1000 ..";"..e*1000 ..";"..f..";"..g*-1)

-- Actual Watt Usage incl Fase 1,2,3
local idWatt = {idx value}
domoticz_updateDevice(idWatt,'',w)
local idWatt = {idx value}
domoticz_updateDevice(idWatt,'',L1)
local idWatt = {idx value}
domoticz_updateDevice(idWatt,'',L2)
local idWatt = {idx value}
domoticz_updateDevice(idWatt,'',L3)

-- Actual Usage 2
local idWatt = {idx value}
domoticz_updateDevice(idWatt,'',w)

--
-- Watermeter
--
local idWater = {idx value}
local m = domoticz_applyJsonPath(s,'.active_liter_lpm')
domoticz_updateDevice(idWater,'',m)

local idWaterTotaal = {idx value}
local n = domoticz_applyJsonPath(s,'.total_liter_m3')
domoticz_updateDevice(idWaterTotaal,'',n)

BTW it's also possible to read voltage from phase 1 upto 3 through Telegram values in DZVentz

Code: Select all

local scriptVar = 'readTelegram'

return
{
    on =
    {
        timer =
        {
            'every minute',
        },
        httpResponses =
        {
            scriptVar,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },

    execute = function(dz, item)

        local debug = _G.logLevel == dz.LOG_DEBUG

        local voltL1 = dz.devices('Input Voltage L1') -- change to name of your virtual voltage device
        local voltL2 = dz.devices('Input Voltage L2') -- change to name of your virtual voltage device
        local voltL3 = dz.devices('Input Voltage L3') -- change to name of your virtual voltage device

        local frequency = 6 -- every 60 / frequency seconds
        local P1Reference =
        {
             voltageL1 = '32.7.0',
             voltageL2 = '52.7.0',
             voltageL3 = '72.7.0',
        }

        local function openURL(delay)
            dz.openURL(
            {
                url = 'http://{ipaddress_from_meter}/api/v1/telegram',
                callback = scriptVar,
            }).afterSec(delay or 0)
        end

        function table.invert(t)
           local it = {}
           for k,v in pairs(t) do
             it[v]=k
           end
           return it
        end

        local function readResult( telegram, it )

            local function crLines(s)
                return s:gsub('\r\n?', '\n'):gmatch('(.-)\n') -- Normalize CR/LF
            end

            local lines = {}
            for line in crLines(telegram) do
                if line:find(':') then
                    key = it[line:match(':(%d+.%d+.%d+)')]
                    if key then
                        lines[key] = math.floor((line:match('%b()%s*%c*$'):match('%d+%.*%d*') or -1) * 1000)
                    end
                end
            end

            if debug then dz.utils.dumpTable(lines) end

            return lines

        end

        local function updateDevices(t)
            
            voltL1.updateVoltage( dz.utils.round( t.voltageL1 / 1000 ,1 ) )
            voltL2.updateVoltage( dz.utils.round( t.voltageL2 / 1000 ,1 ) )
            voltL3.updateVoltage( dz.utils.round( t.voltageL3 / 1000 ,1 ) )

        end

        local function showResults(t, it)
            if not(debug) then return end
            for code, value in pairs(t) do
                if it[code] then
                    dz.log(it[code] .. ' ==>> ' .. value, dz.LOG_DEBUG)
                end
            end
        end

        -- main code
        if item.isTimer then
            openURL()

            local interval = math.floor(60/frequency)
            for secondsDelay = interval, (60 - interval), interval do
                openURL(secondsDelay)
            end
        elseif item.isHTTPResponse and item.ok then
            local invertedTable = table.invert(P1Reference)

            local actual = readResult(item.data, invertedTable)
            showResults(actual, invertedTable)
            updateDevices(actual, invertedTable)
        else
            dz.log('Problem reading the telegram', dz.LOG_ERROR)
            dz.log(tostring(item.data), dz.LOG_DEBUG)
        end
    end
}










Pheinstra wrote: Wednesday 28 September 2022 20:48 I know it has been quite some time since this post was active.
I have just purchased a Homewizard P1 meter and used this method and it works like a charm! So thanks for that.

I was wondering if it is also possible to get readings on the seperate fases.......does anyone know how to do that properly? I have managed to get readings on the current usage for the different fases by changing the "f" (in the "domoticz_updateDevice" part) in the letters of the fases (so, 1 for G, 1 for H and 1 for I). but the graphs in the log of the device still show the total usage of the 3 fases combined...... as i sometimes have weird peaks in the total amount i want to find out on which fase they occur.
I am quite a noob (or maybe even a total noob :) ) on scripting........

Thanks in advance for your help!!

Regards,

Koen
Last edited by SanderRoelofs on Monday 02 January 2023 15:26, edited 1 time in total.
SanderRoelofs
Posts: 17
Joined: Thursday 11 March 2021 10:03
Target OS: Windows
Domoticz version:
Contact:

Re: Using P1-device form Dutch Homewizard

Post by SanderRoelofs »

I had the same error with my new meter. This problem occurs because the gas meter isn't connected to the p1 meter.
you can disable gasmeter readings until it works or i did this

if a == not nil then domoticz_updateDevice(idGas,'',a*1000) else domoticz_updateDevice(idGas,'',{manual_value}*1000) end

update my readings once a day manual.
guidohuijnen wrote: Saturday 01 October 2022 18:32 I'm a complete noob with Lua...

Can someone help why I get this error:

input:3: attempt to index a nil value (global 'request')

Thnx & regards,
Guido
User avatar
waltervl
Posts: 5714
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Using P1-device form Dutch Homewizard

Post by waltervl »

@SanderRoeloefs

It would be nice if you modified your posts with code so that the code comes in code brackets and becomes readable.... :D

Code: Select all

code
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
SanderRoelofs
Posts: 17
Joined: Thursday 11 March 2021 10:03
Target OS: Windows
Domoticz version:
Contact:

Re: Using P1-device form Dutch Homewizard

Post by SanderRoelofs »

Sorry and done
waltervl wrote: Monday 02 January 2023 14:33 @SanderRoeloefs

It would be nice if you modified your posts with code so that the code comes in code brackets and becomes readable.... :D

Code: Select all

code
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest