Page 1 of 1

Read out data from a z wave sensor from domoticz and pass to OpenWB with http

Posted: Wednesday 17 February 2021 23:47
by lumjajo
Hi,
I need to read out the data (Energy) of a Z Wave Plug from Domoticz.
This should be done with the API as OpenWB requires a http url.
If I read the Domoticz API Wiki page, it only tells me how tomodify the calues of a sensor, not to read the data of a z wave device. Can someony please just poin tme into the right direction?
Thanks

Re: Read out data from a z wave sensor from domoticz and pass to OpenWB with http

Posted: Thursday 18 February 2021 11:22
by waltervl
You can use HTTPlink for that: setup > more options > data push > HTTP
see also https://www.domoticz.com/wiki/HttpLink On that wike page there is an example how to send data to an influx database but the same can be done to somthing as OpenWB.


Alternative you can create a DzVents script that sends the data with domoticz.OpenURL see https://www.domoticz.com/wiki/DzVents:_ ... terface.29

Re: Read out data from a z wave sensor from domoticz and pass to OpenWB with http

Posted: Thursday 18 February 2021 11:39
by waaren
lumjajo wrote: Wednesday 17 February 2021 23:47 I need to read out the data (Energy) of a Z Wave Plug from Domoticz.
Is the information needed not already in the result of the standard device API?

Code: Select all

http://<domoticz IP:domoticz Port>/json.htm?type=devices&rid=<device idx>
Spoiler: show

Code: Select all

{
	"ActTime" : 1613644456,
	"AstrTwilightEnd" : "19:54",
	"AstrTwilightStart" : "05:57",
	"CivTwilightEnd" : "18:36",
	"CivTwilightStart" : "07:15",
	"DayLength" : "10:12",
	"NautTwilightEnd" : "19:15",
	"NautTwilightStart" : "06:36",
	"ServerTime" : "2021-02-18 11:34:16",
	"SunAtSouth" : "12:56",
	"Sunrise" : "07:50",
	"Sunset" : "18:02",
	"app_version" : "2020.2 (build 12947)",
	"result" : 
	[
		{
			"AddjMulti" : 1.0,
			"AddjMulti2" : 1.0,
			"AddjValue" : 0.0,
			"AddjValue2" : 0.0,
			"BatteryLevel" : 255,
			"CounterToday" : "-0.000 kWh",
			"CustomImage" : 0,
			"Data" : "112.521 kWh",
			"Description" : "",
			"EnergyMeterMode" : "",
			"Favorite" : 0,
			"HardwareDisabled" : false,
			"HardwareID" : 4,
			"HardwareName" : "Aeotec  Zwave stick",
			"HardwareType" : "OpenZWave USB",
			"HardwareTypeVal" : 21,
			"HaveTimeout" : false,
			"ID" : "00000301",
			"LastUpdate" : "2021-02-18 08:55:31",
			"Name" : "Wasmachine Kw",
			"Notifications" : "false",
			"PlanID" : "0",
			"PlanIDs" : 
			[
				0
			],
			"Protected" : false,
			"ShowNotifications" : true,
			"SignalLevel" : "-",
			"SubType" : "kWh",
			"SwitchTypeVal" : 0,
			"Timers" : "false",
			"Type" : "General",
			"TypeImg" : "current",
			"Unit" : 1,
			"Usage" : "0.1 Watt",
			"Used" : 1,
			"XOffset" : "0",
			"YOffset" : "0",
			"idx" : "915"
		}
	],
	"status" : "OK",
	"title" : "Devices"
}

Re: Read out data from a z wave sensor from domoticz and pass to OpenWB with http

Posted: Thursday 18 February 2021 14:02
by waltervl
BTW: If you want to communicate with OpenWB you better can use MQTT: https://openwb.de/forum/viewtopic.php?f=6&t=577
But I think there is no way to send the Energy values of your Zwave device to OpenWB??? You can only set charge modes....

Re: Read out data from a z wave sensor from domoticz and pass to OpenWB with http

Posted: Thursday 18 February 2021 18:33
by lumjajo
The problem is the smarthome 2.0 connection to the sensor. Its either Shelly or Tasmota or http no Mqtt. I would really like to do it with MQTT. I just thought having domoticz available I use one of the sensores there. I need a power sensor, which feeds back the information to OpenWB. Unfortunately openWB does not suppurt ESP Easy...would also be an option ....

Ok I understand that I cannot read out the Current, Power from a Z wave Device with simple http url. Therefore I assume i need to create something different....

@warren, yes it does but openWB does not know what to do with all the information.

Code: Select all

ActTime	1613668859
AstrTwilightEnd	"19:24"
AstrTwilightStart	"05:30"
CivTwilightEnd	"18:12"
CivTwilightStart	"06:42"
DayLength	"10:26"
NautTwilightEnd	"18:48"
NautTwilightStart	"06:06"
ServerTime	"2021-02-18 18:20:59"
SunAtSouth	"12:27"
Sunrise	"07:14"
Sunset	"17:40"
app_version	"4.10717"
result	
0	
AddjMulti	1
AddjMulti2	1
AddjValue	0
AddjValue2	0
BatteryLevel	255
CounterToday	"0.020 kWh"
CustomImage	0
Data	"0.020 kWh"
Description	""
EnergyMeterMode	"0"
Favorite	0
HardwareID	4
HardwareName	"ZWave USB"
HardwareType	"OpenZWave USB"
HardwareTypeVal	21
HaveTimeout	false
ID	"00002201"
LastUpdate	"2021-02-18 18:20:24"
Name	"Neo Coolcam Plug 2 Energie"
Notifications	"false"
PlanID	"12"
PlanIDs	
0	12
Protected	false
ShowNotifications	true
SignalLevel	"-"
SubType	"kWh"
SwitchTypeVal	0
Timers	"false"
Type	"General"
TypeImg	"current"
Unit	1
Usage	"0 Watt"
Used	1
XOffset	"548"
YOffset	"167"
idx	"428"
status	"OK"
title	"Devices"
and I am not smart enough to tell openWb with a http url which value it should pick....gues thats not working at all.

Thanks anyway for your help...:-)

Re: Read out data from a z wave sensor from domoticz and pass to OpenWB with http

Posted: Thursday 18 February 2021 18:56
by waltervl
I cannot understand what you want to do. Can you give a link to the documentation or manual were is described that openWB can read energy data from an external device with an http link?

Re: Read out data from a z wave sensor from domoticz and pass to OpenWB with http

Posted: Friday 19 February 2021 18:33
by lumjajo
Here its strange but its one of the options .

Image

I understand now that its not possible, so I will by a shelly...this will be supported by OpenWB.
In the Drop Down Menue it says:
Shelly,Tasmota,Acthor,Elwa,IDM ,Stiebel,Http,AVM,MyStrom

Re: Read out data from a z wave sensor from domoticz and pass to OpenWB with http

Posted: Friday 19 February 2021 19:31
by waltervl
What is a possibility is to create a php script that will show the value when called eg http://IP-domoticz:port/extract.php?idx=xxx

See for example
https://www.domoticz.com/wiki/Extractin ... s_with_PHP

Re: Read out data from a z wave sensor from domoticz and pass to OpenWB with http

Posted: Friday 19 February 2021 22:28
by lumjajo
Interesting, I did not know it and will have a look.
Basically the easiest way is to buy a shelly...this can be used natively...and even can be connected with domoticz

Re: Read out data from a z wave sensor from domoticz and pass to OpenWB with http

Posted: Wednesday 24 February 2021 21:58
by waltervl
I have a solution for you (if I am not too late and you bought already a Shelly :-) ):
  • Create a getvalue.html file and copy the code into this file.
  • Save this getvalue.html file in domoticz/www/views
  • Change the line with $.domoticzurl="http://<IP-of-server>:<port>"; to the correct IP adress and port of your domoticz server
  • Use the following link http://<IP>:<port>/views/getvalue.html?idx=xxx&type=yyy to get the requested value as plain text (as requested by OpenWB)
idx is the idx number of the device
type (case sensitive!) is the type of the requested value from the json of your idx device (http://<IP-of-server>:<port>/json.htm?type=devices&rid=idx) like from below example :
type=Data will give 3.14 (the data is cleaned by the html file)
type=BatteryLevel will give 255

If the page cannot read a value due to for example type error it will give the value ??

So for below example device 113 to get the value Data you should enter the following link http://<IP-of-server>:<port>/views/getvalue.html?idx=113&type=Data

example json of idx 113:

Code: Select all

{
	"ActTime" : 1614199414,
	"AstrTwilightEnd" : "20:01",
	"AstrTwilightStart" : "05:43",
	"CivTwilightEnd" : "18:44",
	"CivTwilightStart" : "07:00",
	"DayLength" : "10:37",
	"NautTwilightEnd" : "19:23",
	"NautTwilightStart" : "06:21",
	"ServerTime" : "2021-02-24 21:43:34",
	"SunAtSouth" : "12:52",
	"Sunrise" : "07:34",
	"Sunset" : "18:10",
	"app_version" : "2020.2 (build 12901)",
	"result" : 
	[
		{
			"AddjMulti" : 1.0,
			"AddjMulti2" : 1.0,
			"AddjValue" : 0.0,
			"AddjValue2" : 0.0,
			"BatteryLevel" : 255,
			"CustomImage" : 0,
			"Data" : "3.14 Watt",
			"Description" : "",
			"Favorite" : 0,
			"HardwareDisabled" : false,
			"HardwareID" : 8,
			"HardwareName" : "ZiGate",
			"HardwareType" : "Zigate plugin",
			"HardwareTypeVal" : 94,
			"HaveTimeout" : false,
			"ID" : "00158d00032d3827",
			"LastUpdate" : "2021-02-24 21:42:55",
			"Name" : "ZiGate - Power-00158d00032d3827-02",
			"Notifications" : "false",
			"PlanID" : "1",
			"PlanIDs" : 
			[
				1
			],
			"Protected" : false,
			"ShowNotifications" : true,
			"SignalLevel" : 9,
			"SubType" : "Electric",
			"Timers" : "false",
			"Type" : "Usage",
			"TypeImg" : "current",
			"Unit" : 23,
			"Used" : 1,
			"XOffset" : "0",
			"YOffset" : "0",
			"idx" : "113"
		}
	],
	"status" : "OK",
	"title" : "Devices"
}
getvalue.html (to be saved in folder domoticz/www/views):

Code: Select all

<!DOCTYPE html>
<html lang="en">
<head>
<!-- Use the following link http://<IP>:<port>/views/getvalue.html?idx=xxx&type=yyy to get the requested value as plain text -->
<!-- idx is the idx number of the device -->
<!-- type (case sensitive!) is the type of the requested value from the json of your idx device -->
<!-- change line $.domoticzurl="http://<IP-of-server>:<port>" to match your domoticz  IP and port -->
<meta charset="utf-8">
<title>GetValue</title> 
<script src="http://code.jquery.com/jquery-3.5.1.min.js"></script>
<style>
div#cnt 
</style>
</head>
<div id="iusage">--</div>
<script type="text/javascript" charset="utf-8">
function RefreshData()
{
	clearInterval($.refreshTimer);
	var jurl=$.domoticzurl+"/json.htm?type=devices&rid="+$.getIDX;
	$.getJSON(jurl,
	{
		format: "json"
	},
	function(data) {
		if (typeof data.result != 'undefined') {
			if (typeof data.WindSign != 'undefined') {
				$('.windsign').html(data.WindSign);
			}
			if (typeof data.TempSign != 'undefined') {
				$('.degsign').html(data.TempSign);
			}
			$.each(data.result, function(i,item) {
					if( $.getIDX === item.idx ) {
						var vdata=item[$.vtype];
						if (typeof vdata == 'undefined') {
							vdata="??";
						}
						else {
							vdata=new String(vdata).split(" ",1)[0];
						}
						$('#iusage').html(vdata);
					}
			});
		}
	});
	$.refreshTimer = setInterval(RefreshData, 10000);
}
function getAllUrlParams(url) {
  var queryString = url ? url.split('?')[1] : window.location.search.slice(1);
  var obj = {};

  if (queryString) {
    queryString = queryString.split('#')[0];
    var arr = queryString.split('&');

    for (var i = 0; i < arr.length; i++) {
      var a = arr[i].split('=');
      var paramName = a[0];
      var paramValue = typeof (a[1]) === 'undefined' ? true : a[1];

      //paramName = paramName.toLowerCase();
      //if (typeof paramValue === 'string') paramValue = paramValue.toLowerCase();

      if (paramName.match(/\[(\d+)?\]$/)) {
        var key = paramName.replace(/\[(\d+)?\]/, '');
        if (!obj[key]) obj[key] = [];

        if (paramName.match(/\[\d+\]$/)) {
          var index = /\[(\d+)\]/.exec(paramName)[1];
          obj[key][index] = paramValue;
        } else {
          obj[key].push(paramValue);
        }
      } else {
        if (!obj[paramName]) {
          obj[paramName] = paramValue;
        } else if (obj[paramName] && typeof obj[paramName] === 'string'){
          obj[paramName] = [obj[paramName]];
          obj[paramName].push(paramValue);
        } else {
          obj[paramName].push(paramValue);
        }
      }
    }
  }

  return obj;
}

$(document).ready(function() {
       // change next line to match your domoticz  IP and port
	$.domoticzurl="http://<IP-of-server>:<port>";
	$.getIDX = getAllUrlParams().idx;
	$.vtype = getAllUrlParams().type;
	
    RefreshData();
});  
</script>

</body>
</html>

Re: Read out data from a z wave sensor from domoticz and pass to OpenWB with http

Posted: Sunday 07 March 2021 17:04
by Pvhpsb
Hello Walter, thanks for this info I can now read the correct data in a web browser with getvalue link.
But unfortunately it doesn't work in openWB, you know someone who have this working with openWB.
With kind regards,
Patrick

Re: Read out data from a z wave sensor from domoticz and pass to OpenWB with http

Posted: Sunday 07 March 2021 17:21
by waltervl
I am sorry, perhaps someone on openWB forum can help...

Re: Read out data from a z wave sensor from domoticz and pass to OpenWB with http

Posted: Saturday 13 March 2021 11:29
by lumjajo
I tried it as well, but did not work for me either..yes I bought a Shelly but did not use it so far...