Page 1 of 1

Smappee

Posted: Tuesday 03 April 2018 10:28
by matteos1
is it possible to introduce smappee in domoticz natively?

Re: Smappee

Posted: Friday 06 April 2018 7:46
by matteos1
anyone that have resolved this?

Re: Smappee

Posted: Friday 06 April 2018 8:31
by Egregius
Use a script to query the smappee and push the data to domoticz.

Re: Smappee

Posted: Friday 06 April 2018 10:19
by Egregius
This is what I do with it:

Code: Select all

<?php
$smappee=json_decode(file_get_contents('http://192.168.2.19/gateway/apipublic/reportInstantaneousValues'),true);
if(!empty($smappee['report'])){
	$zon=apcu_fetch('zon');
	preg_match_all("/ activePower=(\\d*.\\d*)/",$smappee['report'],$matches);
	if(!empty($matches[1][1])){
		$newzon=round($matches[1][1],0);
		if($newzon<0)$newzon=0;
		if($zon!=$newzon)apcu_store('zon',$newzon);
		if(!empty($matches[1][2])){
			$consumption=round($matches[1][2],0);
			if($consumption!=apcu_fetch('verbruik'))apcu_store('verbruik',$consumption);
			$timestamp=strftime("%Y-%m-%d %H:%M:%S",time());
			$query="INSERT INTO `smappee` (`timestamp`,`consumption`) VALUES ('$timestamp','$consumption');";
			$db=new mysqli('127.0.0.1','domotica','domotica','domotica');if($db->connect_errno>0)die('Unable to connect to database [' . $db->connect_error . ']');if(!$result=$db->query($query))die('There was an error running the query ['.$query .' - ' . $db->error . ']');$db->close();
			if($consumption>8000){
				if(past('notify_power')>3600){
					apcu_store('Tnotify_power',time());
					telegram('Power usage: '.$consumption.' W!',false);
				}
			}
		}
	}
}else{
	if(shell_exec('curl -H "Content-Type: application/json" -X POST -d "" http://192.168.2.19/gateway/apipublic/logon')!='{"success":"Logon successful!","header":"Logon to the monitor portal successful..."}')exit;
}
function past($name){return time()-apcu_fetch('T'.$name);}
function telegram($msg,$silent=true,$to=1){
	$msg=str_replace('__',PHP_EOL,$msg);
	shell_exec('/var/www/html/secure/telegram.sh "'.$msg.'" "'.$silent.'" "'.$to.'" > /dev/null 2>/dev/null &');
}
?>
Above script is executed every 10 seconds. It gives me the current power consumption and solar power. The data is stored in a SQL database and is the consumption is more than 8000W I receive a message.


And then in a cron job that runs every 2 minutes:

Code: Select all

$timefrom=time-86400;
$chauth = curl_init('https://app1pub.smappee.net/dev/v1/oauth2/token?grant_type=password&client_id='.$smappeeclient_id.'&client_secret='.$smappeeclient_secret.'&username='.$smappeeusername.'&password='.$smappeepassword.'');
curl_setopt($chauth,CURLOPT_AUTOREFERER,true);
curl_setopt($chauth,CURLOPT_RETURNTRANSFER,1);
curl_setopt($chauth,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($chauth,CURLOPT_VERBOSE,1);
curl_setopt($chauth,CURLOPT_SSL_VERIFYHOST,false);
curl_setopt($chauth,CURLOPT_SSL_VERIFYPEER,false);
$objauth=json_decode(curl_exec($chauth));
if(!empty($objauth)){
	$access=$objauth->{'access_token'};
	curl_close($chauth);
	$chconsumption=curl_init('');
	curl_setopt($chconsumption,CURLOPT_HEADER,0);
	$headers=array('Authorization: Bearer '.$access);
	curl_setopt($chconsumption,CURLOPT_HTTPHEADER,$headers);
	curl_setopt($chconsumption,CURLOPT_AUTOREFERER,true);
	curl_setopt($chconsumption,CURLOPT_URL,'https://app1pub.smappee.net/dev/v1/servicelocation/'.$smappeeserviceLocationId.'/consumption?aggregation=3&from='.$timefrom.'000&to='.time.'000');
	curl_setopt($chconsumption,CURLOPT_RETURNTRANSFER,1);
	curl_setopt($chconsumption,CURLOPT_FOLLOWLOCATION,1);
	curl_setopt($chconsumption,CURLOPT_VERBOSE,1);
	curl_setopt($chconsumption,CURLOPT_SSL_VERIFYHOST,false);
	curl_setopt($chconsumption,CURLOPT_SSL_VERIFYPEER,false);
	$objconsumption=json_decode(curl_exec($chconsumption),true);
	if(!empty($objconsumption['consumptions'])){
		$verbruikvandaag=$objconsumption['consumptions'][0]['consumption']/1000;
		apcu_store('verbruikvandaag',round($verbruikvandaag,1));
		$zonvandaag=$objconsumption['consumptions'][0]['solar']/1000;
		apcu_store('zonvandaag',round($zonvandaag,1));
		$gas=apcu_fetch('gasvandaag')/100;
		$water=apcu_fetch('watervandaag')/1000;
		@file_get_contents("https://xxx.xxx.xxx/secure/insertdata.php?user=xxx&verbruik=$verbruikvandaag&gas=$gas&water=$water&zon=$zonvandaag");
		lg("verbruik => gas = $gas | verbruik = $verbruikvandaag | zon = $zonvandaag | water = $water");
	}
	curl_close($chconsumption);
}
Here I grab the daily totals and push them to php cache so I can see them on my floorplan and they're sent to a site where I monitor consumptions together with some friends.

Re: Smappee

Posted: Friday 06 April 2018 19:40
by matteos1
if would i control the plug?

Re: Smappee

Posted: Friday 06 April 2018 19:48
by Egregius
You didn't specify that...
I don't have any smappee plugs but I guess you can easily grab the url from developper console from your browser.

Re: Smappee

Posted: Saturday 07 April 2018 0:09
by simonrg
Have you looked in the Wiki?
https://www.domoticz.com/wiki/Smappee

Re: Smappee

Posted: Saturday 07 April 2018 5:29
by Egregius
@simonrg
If you remove the code block the link will be clickable.

Re: Smappee

Posted: Saturday 07 April 2018 15:50
by simonrg
Egregius wrote: Saturday 07 April 2018 5:29 @simonrg
If you remove the code block the link will be clickable.
Thanks, I meant to use:

Code: Select all

[url]http://www.domoticz.com/wiki[/url]
not the code one, as just pasting in the url leads to truncation, so you can't see where you are going.

Re: Smappee

Posted: Thursday 10 May 2018 12:32
by matteos1
this is new specific send by smappe organizzation to me to control plug with mqtt system
Smappee local MQTT topics - 20180209 (1).pdf
(23 KiB) Downloaded 198 times
MQTT broker configuration on Smappee Plus Pro (1).pdf
(190.71 KiB) Downloaded 142 times
if someone can create script to control plug with mqtt system
thank a lot

Re: Smappee

Posted: Thursday 17 May 2018 23:20
by simonrg
Great, I haven't used MQTT at all, but it looks like it should simple to talk to Smappee via MQTT.

However, there needs to be some programming to translate Smappee MQTT messasges which into MQTT messages which Domoticz would understand and for Domoticz MQTT to be transleted for Smappee.

Time to read the wiki - https://www.domoticz.com/wiki/MQTT and look at other people using MQTT https://www.sigmdel.ca/michel/ha/domo/domo_03_en.html.

I sse you have already posted in the MQTT support thread - http://www.domoticz.com/forum/viewtopic ... &start=320