Page 1 of 1

P1 USB smart meter - Actual tariff

Posted: Thursday 16 July 2020 12:02
by sjoerd1953
I have a smart meter for a few weeks now. It is connected to a Raspberry Pi running Domoticz. Everything works fine but the only information I am missing is the actual tariff (high or low). This information is available in the telegram as item 0-0:96.14.0(0001) or 0-0:96.14.0(0002). Domoticz obviously uses this setting when creating the 24h graph but I can't find it anywhere in the database. Does someone know how to access this information?

Re: P1 USB smart meter - Actual tariff

Posted: Thursday 16 July 2020 12:16
by waaren
sjoerd1953 wrote: Thursday 16 July 2020 12:02 Does someone know how to access this information?
Domoticz use this information indirectly. When the low tariff is active only the low tariff kWh counter does increase and if the high tariff is active the high kWh tariff counter increase

Re: P1 USB smart meter - Actual tariff

Posted: Thursday 16 July 2020 13:21
by sjoerd1953
Thank you for the reply. So Domoticz has no knowledge of the actual tariff.

As an alternative, is possible to write a script that gets this information from the original telegram as it is sent by the smart meter and put it in a virtual sensor.

I can read the the original telegram in Node-RED using the serial-in node but I can't have both systems (Domoticz and Node-RED) to use the USB port at the same time. That gives errors in one of them.

Re: P1 USB smart meter - Actual tariff

Posted: Thursday 16 July 2020 16:04
by waaren
sjoerd1953 wrote: Thursday 16 July 2020 13:21 As an alternative, is possible to write a script that gets this information from the original telegram as it is sent by the smart meter and put it in a virtual sensor.
You can try with below dzVents script

When not yet familiar with dzVents please start with reading Get started Before implementing (~ 5 minutes). Special attention please for "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents enabled' is checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."

Code: Select all

return
{
    on =
    {
        timer =
        {
            'at 06:30-07:30 every 5 minutes on mon,tue,wed,thu,fri', 
            'at 20:30-21:30 every 5 minutes on mon,tue,wed,thu,fri', -- when tariff switch is around 21:00
            'at 22:30-23:30 every 5 minutes on mon,tue,wed,thu,fri', -- when tariff switch is around 23:00
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when script is OK
        marker = 'tariff',
    },

    data =
    {
        highTariff = { initial = 0 },
        lowTariff = { initial = 0 },
    },

    execute = function(dz, item)
        local p1 = dz.devices('Power') -- change to name of smartmeter
        local tariffSensor = dz.devices('tariffSensor') -- change to name of textSensor

        dz.log(p1.usage1,dz.LOG_DEBUG)
        dz.log(p1.usage2,dz.LOG_DEBUG)
        dz.log(p1.return1,dz.LOG_DEBUG)
        dz.log(p1.return2,dz.LOG_DEBUG)

        if ( p1.usage2 + p1.return2) ~= dz.data.highTariff then
            tariffSensor.updateText('High tariff')
            dz.data.highTariff = p1.usage2 + p1.return2
        elseif ( p1.usage1 + p1.return1) ~= dz.data.lowTariff then
            tariffSensor.updateText('Low tariff')
            dz.data.lowTariff = p1.usage1 + p1.return1
        end
    end
}

Re: P1 USB smart meter - Actual tariff

Posted: Thursday 16 July 2020 17:06
by sjoerd1953
Thank you waaren. At the moment I am getting High tariff as a result. Now wait until 9PM tonight to see if it changes. I am not sure yet why it works but I will figure that out the next few hours :D .

Re: P1 USB smart meter - Actual tariff

Posted: Thursday 16 July 2020 17:34
by waaren
sjoerd1953 wrote: Thursday 16 July 2020 17:06 At the moment I am getting High tariff as a result. Now wait until 9PM tonight to see if it changes.
Made some required adjustments to the script in my earlier post to prevent toggling between the two tariffs :) . Please replace the previous one with the updated.

Re: P1 USB smart meter - Actual tariff

Posted: Friday 17 July 2020 8:31
by sjoerd1953
It didn't work yet. The values of highTariff and lowTariff stayed nill. I made some changes and now it seems to work:

Code: Select all

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

    logging =
    {
        level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when script is OK
        marker = 'tariff',
    },

    data =
    {
        
        highTariff = { initial = 0 },
        lowTariff = { initial = 0 }
        
    },
    

    execute = function(dz, item)
        local p1 = dz.devices('Stroom')
        local tariffSensor = dz.devices('Tarief')

        dz.log(p1.usage1,dz.LOG_DEBUG)
        dz.log(p1.return1,dz.LOG_DEBUG)
        dz.log(dz.data.lowTariff,dz.LOG_DEBUG)
        
        dz.log(p1.usage2,dz.LOG_DEBUG)
        dz.log(p1.return2,dz.LOG_DEBUG)
        dz.log(dz.data.highTariff,dz.LOG_DEBUG)

        if ( p1.usage2 + p1.return2) ~= dz.data.highTariff then
            tariffSensor.updateText('Hoog tarief')
            dz.data.highTariff = p1.usage2 + p1.return2
            dz.log(dz.data.highTariff,dz.LOG_DEBUG)
        elseif ( p1.usage1 + p1.return1) ~= dz.data.lowTariff then
            tariffSensor.updateText('Laag tarief')
            dz.data.lowTariff = p1.usage1 + p1.return1
            dz.log(dz.data.lowTariff,dz.LOG_DEBUG)
        end
    end
}

Re: P1 USB smart meter - Actual tariff

Posted: Friday 17 July 2020 8:50
by waaren
sjoerd1953 wrote: Friday 17 July 2020 8:31 It didn't work yet. The values of highTariff and lowTariff stayed nill. I made some changes and now it seems to work:
:) Good that it is working now. Still some optimization possible by modifying the timer = section. This to ensure the script will only start around the times the tariff will switch.
like below

Code: Select all

return
{
    on =
    {
        timer =
        {
            'at 06:30-07:30 every 5 minutes on mon,tue,wed,thu,fri', 
            'at 20:30-21:30 every 5 minutes on mon,tue,wed,thu,fri', -- when tariff switch is around 21:00
            'at 22:30-23:30 every 5 minutes on mon,tue,wed,thu,fri', -- when tariff switch is around 23:00
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when script is OK
        marker = 'tariff',
    },

    data =
    {
        highTariff = { initial = 0 },
        lowTariff = { initial = 0 },
    },

    execute = function(dz, item)
        local p1 = dz.devices('Power') -- change to name of smartmeter
        local tariffSensor = dz.devices('tariffSensor') -- change to name of textSensor

        dz.log(p1.usage1,dz.LOG_DEBUG)
        dz.log(p1.usage2,dz.LOG_DEBUG)
        dz.log(p1.return1,dz.LOG_DEBUG)
        dz.log(p1.return2,dz.LOG_DEBUG)

        if ( p1.usage2 + p1.return2) ~= dz.data.highTariff then
            tariffSensor.updateText('High tariff')
            dz.data.highTariff = p1.usage2 + p1.return2
        elseif ( p1.usage1 + p1.return1) ~= dz.data.lowTariff then
            tariffSensor.updateText('Low tariff')
            dz.data.lowTariff = p1.usage1 + p1.return1
        end
    end
}

Re: P1 USB smart meter - Actual tariff

Posted: Friday 17 July 2020 9:18
by EddyG
You could even narrow it down a lot more.
In my case the switch is almost exactly at 07:00 and 23:00
I can see that on Domoticz graphs, because only at those exact time I see both value.
Domoticz has a 5 min. graph.
Perhaps you could even narrow it down to only 06:55 and 07:05 and 22:55 and 23:05
@sjoerd1953 Just curious, where do you use it for?

Re: P1 USB smart meter - Actual tariff

Posted: Friday 17 July 2020 12:47
by waaren
EddyG wrote: Friday 17 July 2020 9:18 Perhaps you could even narrow it down to only 06:55 and 07:05 and 22:55 and 23:05
True but it also depends on the frequency of the script within those windows. In some areas of the Netherlands the evening switch time is 21:00.

Re: P1 USB smart meter - Actual tariff

Posted: Saturday 18 July 2020 7:43
by sjoerd1953
@waaren That is correct. I live in Limburg and here the change to low tariff is at 21:00
@EddyG No particular use. I was just curious if it was possible. Nice side effect is that I got introduced to dzVents by waaren. I love the way it works :D

Re: P1 USB smart meter - Actual tariff

Posted: Thursday 27 April 2023 8:28
by EdwinK
Found this old topic.

Not sure if it is possible at all, but would it be possible that the sensor switches if/when the company sends a signal to switch from high to low? So, that it isn't depend on time, but on a signal>