Omnik data to openWB with Mqtt  [Solved]

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

Moderator: leecollings

Post Reply
Pvhpsb
Posts: 15
Joined: Tuesday 20 January 2015 13:38
Target OS: NAS (Synology & others)
Domoticz version:
Location: Prinsenbeek
Contact:

Omnik data to openWB with Mqtt

Post by Pvhpsb »

I would like to send my Omnik data "Countertoday" and "Usage" with MQTT publish to my openWB (Charging station), but I am not very familiar with Dzvents. Please help.

This need openWb

Per MQTT zu schreiben:
openWB/set/pv/1/W PV-Leistung in Watt, int, negativ
openWB/set/pv/1/WhCounter Erzeugte Energie in Wh, float, nur positiv



Output Omnik/PVoutput
Spoiler: show

Code: Select all

{
	"ActTime" : 1621608438,
	"AstrTwilightEnd" : "01:19",
	"AstrTwilightStart" : "01:56",
	"CivTwilightEnd" : "22:19",
	"CivTwilightStart" : "04:57",
	"DayLength" : "15:56",
	"NautTwilightEnd" : "23:19",
	"NautTwilightStart" : "03:56",
	"ServerTime" : "2021-05-21 16:47:18",
	"SunAtSouth" : "13:38",
	"Sunrise" : "05:40",
	"Sunset" : "21:36",
	"app_version" : "2021.1",
	"result" : 
	[
		{
			"AddjMulti" : 1.0,
			"AddjMulti2" : 1.0,
			"AddjValue" : 0.0,
			"AddjValue2" : 0.0,
			"BatteryLevel" : 255,
			"CounterToday" : "2.160 kWh",                   *************************************************
			"CustomImage" : 0,
			"Data" : "6459.180 kWh",
			"Description" : "192.168.178.12",
			"EnergyMeterMode" : "",
			"Favorite" : 0,
			"HardwareDisabled" : false,
			"HardwareID" : 4,
			"HardwareName" : "Zonne Panelen",
			"HardwareType" : "PVOutput (Input)",
			"HardwareTypeVal" : 30,
			"HaveTimeout" : false,
			"ID" : "00000001",
			"LastUpdate" : "2021-05-21 16:45:23",
			"Name" : "Zonne Panelen",
			"Notifications" : "false",
			"PlanID" : "0",
			"PlanIDs" : 
			[
				0
			],
			"Protected" : false,
			"ShowNotifications" : true,
			"SignalLevel" : "-",
			"SubType" : "kWh",
			"SwitchTypeVal" : 0,
			"Timers" : "false",
			"Type" : "General",
			"TypeImg" : "current",
			"Unit" : 1,
			"Usage" : "983 Watt",                                  ****************************************
			"Used" : 1,
			"XOffset" : "0",
			"YOffset" : "0",
			"idx" : "12"
		}
	],
	"status" : "OK",
	"title" : "Devices"
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Omnik data to openWB with Mqtt

Post by waaren »

Pvhpsb wrote: Friday 21 May 2021 17:05 I would like to send my Omnik data "Countertoday" and "Usage" with MQTT publish to my openWB (Charging station), but I am not very familiar with Dzvents.
  • What is the type / subtype of this device as seen on the devices tab?
  • What is your domoticz version?
  • Can the domoticz user execute the mosquitto client mosquitto_pub?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Pvhpsb
Posts: 15
Joined: Tuesday 20 January 2015 13:38
Target OS: NAS (Synology & others)
Domoticz version:
Location: Prinsenbeek
Contact:

Re: Omnik data to openWB with Mqtt

Post by Pvhpsb »

1 = 12 Zonne Panelen 00000001 1 Zonne Panelen General kWh 6461.300 kWh - - 2021-05-21 21:35:22

2 = Version: 2021.1
Build Hash: 8547c5b7e
Compile Date: 2021-04-17 17:29:11
dzVents Version: 3.1.7
Python Version: 3.8.6 (default, Jan 27 2021, 15:42:20) [GCC 10.2.0]

3 = Yes i can send publisch messages

Thanks for the quick response.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Omnik data to openWB with Mqtt

Post by waaren »

Pvhpsb wrote: Friday 21 May 2021 21:42 Yes i can send publisch messages
Could look like below

Code: Select all

local scriptVar = 'solar2omnik'
return
{
    on =
    {
        devices =
        {
            'Zonne Panelen',
        },
        shellCommandResponses =
        {
            scriptVar,
        }
    },

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

    execute = function(dz, item)

        if item.isDevice then
            local MQTTBase = "mosquitto_pub " -- or full qualified program name

            local omnikLeistung  = MQTTBase ..' -m ' .. (item.actualWatt * -1) .. ' -t openWB/set/pv/1/W '
            local omnikErzeugt = MQTTBase .. ' -m  '.. item.WhTotal ..  ' -t openWB/set/pv/1/WhCounter '

            dz.executeShellCommand(
            {
                command = omnikLeistung .. '; ' .. omnikErzeugt,
                callback = scriptVar,
                timeout = 10,
            })
        elseif item.isShellCommandResponse then
            if item.statusCode == 0 then
                dz.log('commands processed OK',dz.LOG_DEBUG)
            else
                dz.log('commands processed NOK',dz.LOG_ERROR)
                dz.log(item,dz.LOG_DEBUG)
            end
        end
    end
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Pvhpsb
Posts: 15
Joined: Tuesday 20 January 2015 13:38
Target OS: NAS (Synology & others)
Domoticz version:
Location: Prinsenbeek
Contact:

Re: Omnik data to openWB with Mqtt

Post by Pvhpsb »

Thanks i test it soon.
Pvhpsb
Posts: 15
Joined: Tuesday 20 January 2015 13:38
Target OS: NAS (Synology & others)
Domoticz version:
Location: Prinsenbeek
Contact:

Re: Omnik data to openWB with Mqtt

Post by Pvhpsb »

After changing line 27 I get the correct value in "openWB"
local omnikLeistung = MQTTBase ..' -m ' .. math.floor(item.actualWatt + 0.5) .. ' -t openWB/set/pv/1/W '

Line 28 indicates in "openWB" the total yield "Data" and not the daily yield "CounterToday"

Thank you very much for now.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Omnik data to openWB with Mqtt

Post by waaren »

Pvhpsb wrote: Saturday 22 May 2021 20:48 Line 28 indicates in "openWB" the total yield "Data" and not the daily yield "CounterToday"
So I guess changing line 28 from

Code: Select all

local omnikErzeugt = MQTTBase .. ' -m  '.. item.WhTotal ..  ' -t openWB/set/pv/1/WhCounter '
to

Code: Select all

local omnikErzeugt = MQTTBase .. ' -m  '.. item.counterToday ..  ' -t openWB/set/pv/1/WhCounter '
should fix that ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Pvhpsb
Posts: 15
Joined: Tuesday 20 January 2015 13:38
Target OS: NAS (Synology & others)
Domoticz version:
Location: Prinsenbeek
Contact:

Re: Omnik data to openWB with Mqtt  [Solved]

Post by Pvhpsb »

That's the solution, thank you again.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest