Power consumption from json.  [Solved]

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

Moderator: leecollings

Post Reply
azzilla
Posts: 8
Joined: Tuesday 01 January 2019 16:16
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Power consumption from json.

Post by azzilla »

I am a complete moron when it comes to scripting..
If anyone could have a go at helping me create a script for pulling values from my EV-chargers load balancing energy meter into one or possibly three virtual sensors, I would appreciate it.
The values from the load balancing meter are accessible to me via the EV-chargers IP adress.

Image

The values that are of interest are "phaseXCurrent" and the values shown in the image corresponds to:
"phase1Current: 48" = 4,8A
"phase2Current: 31" = 3,1A
"phase3Current: 5" = 0,5A

The soaring energy prices in country has made a huge crater in my wallet but I am more than happy to contribute to the Domoticz project in any way, shape or form when I can. But as I mentioned, scripting is just above my skillset :D
javalin
Posts: 71
Joined: Tuesday 30 April 2019 16:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Portugal
Contact:

Re: Power consumption from json.

Post by javalin »

Hi, I am not specialist but should be something like this to get phase1Current value in your LOG

Code: Select all

local scriptVar = 'EV-chargers'
return
{
    on =
    {
        timer =
        {
            'every 1 minutes',
        },
        httpResponses =
        {
            scriptVar,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'EV-chargers',
    },

    execute = function(dz, item)

        if item.isTimer then
            dz.openURL({
                url = 'put your http adresse here',
                method = 'GET',
                callback = scriptVar, -- httpResponses above.
            })
            return

        elseif item.json then
            local rt = item.json
            local phase1Current = rt.phase1Current/10 
            dz.log('phase1Current: ' .. phase1Current ..' A' , dz.LOG_DEBUG )
        else
            dz.log('problem with return', dz.LOG_ERROR)
            dz.log(item, dz.LOG_DEBUG)
        end

    end
}
azzilla
Posts: 8
Joined: Tuesday 01 January 2019 16:16
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Power consumption from json.

Post by azzilla »

javalin wrote: Tuesday 01 February 2022 22:52 Hi, I am not specialist but should be something like this to get phase1Current value in your LOG

Code: Select all

local scriptVar = 'EV-chargers'
return
{
    on =
    {
        timer =
        {
            'every 1 minutes',
        },
        httpResponses =
        {
            scriptVar,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'EV-chargers',
    },

    execute = function(dz, item)

        if item.isTimer then
            dz.openURL({
                url = 'put your http adresse here',
                method = 'GET',
                callback = scriptVar, -- httpResponses above.
            })
            return

        elseif item.json then
            local rt = item.json
            local phase1Current = rt.phase1Current/10 
            dz.log('phase1Current: ' .. phase1Current ..' A' , dz.LOG_DEBUG )
        else
            dz.log('problem with return', dz.LOG_ERROR)
            dz.log(item, dz.LOG_DEBUG)
        end

    end
}
I will give it try, thanks!
Do i create a dummy electric and instant counter and name it 'EV-chargers' as you are calling it in the first line of the script?
javalin
Posts: 71
Joined: Tuesday 30 April 2019 16:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Portugal
Contact:

Re: Power consumption from json.  [Solved]

Post by javalin »

Do i create a dummy electric and instant counter and name it 'EV-chargers' as you are calling it in the first line of the script?
Create a dummy Ampere (3 phase), you don´t need to give that name. Just take note of the IDX number and put here instead 628:

Code: Select all

local scriptVar = 'EV-chargers'
return
{
    on =
    {
        timer =
        {
            'every 1 minutes',
        },
        httpResponses =
        {
            scriptVar,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'EV-chargers',
    },

    execute = function(dz, item)
        local EV_charger = dz.devices(628) 
        if item.isTimer then
            dz.openURL({
                url = 'put your http adresses',
                method = 'GET',
                callback = scriptVar, -- httpResponses above.
            })
            return

        elseif item.json then
            local rt = item.json
            local phase1Current = rt.phase1Current/10 
            local phase2Current = rt.phase2Current/10 
            local phase3Current = rt.phase3Current/10 
            dz.log('phase1Current: ' .. phase1Current ..' A' , dz.LOG_DEBUG )
            EV_charger.updateCurrent(phase1Current,phase2Current,phase3Current)          -- store new value in A
        else
            dz.log('problem with return', dz.LOG_ERROR)
            dz.log(item, dz.LOG_DEBUG)
        end

    end
}

azzilla
Posts: 8
Joined: Tuesday 01 January 2019 16:16
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Power consumption from json.

Post by azzilla »

I want to leave this for anyone who might stumble on this thread in the future.


For kWh for all three phases, this works very good.

Code: Select all

local scriptVar = 'EV-chargers'
return
{
    on =
    {
        timer =
        {
            'every 1 minutes',
        },
        httpResponses =
        {
            scriptVar,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'EV-chargers',
    },

    execute = function(dz, item)
        local EV_charger = dz.devices(347) 
        if item.isTimer then
            dz.openURL({
                url = 'input url here',
                method = 'GET',
                callback = scriptVar, -- httpResponses above.
            })
            return

        elseif item.json then
            local rt = item.json
            local phase1Current = rt.phase1Current*23 
            local phase2Current = rt.phase2Current*23 
            local phase3Current = rt.phase3Current*23 
            local sum = phase1Current + phase2Current + phase3Current;
            dz.log('sum of all inputs: ' .. sum ..' W' , dz.LOG_DEBUG )
            EV_charger.updateElectricity(sum)          -- store new value in A
        else
            dz.log('problem with return', dz.LOG_ERROR)
            dz.log(item, dz.LOG_DEBUG)
        end

    end
}

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest