Smappee

Moderator: leecollings

Post Reply
matteos1
Posts: 36
Joined: Monday 08 May 2017 17:29
Target OS: -
Domoticz version:
Contact:

Smappee

Post by matteos1 »

is it possible to introduce smappee in domoticz natively?
matteos1
Posts: 36
Joined: Monday 08 May 2017 17:29
Target OS: -
Domoticz version:
Contact:

Re: Smappee

Post by matteos1 »

anyone that have resolved this?
User avatar
Egregius
Posts: 2589
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Smappee

Post by Egregius »

Use a script to query the smappee and push the data to domoticz.
User avatar
Egregius
Posts: 2589
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Smappee

Post 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.
matteos1
Posts: 36
Joined: Monday 08 May 2017 17:29
Target OS: -
Domoticz version:
Contact:

Re: Smappee

Post by matteos1 »

if would i control the plug?
User avatar
Egregius
Posts: 2589
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Smappee

Post 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.
simonrg
Posts: 329
Joined: Tuesday 16 July 2013 22:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8807
Location: North East England
Contact:

Re: Smappee

Post by simonrg »

Have you looked in the Wiki?
https://www.domoticz.com/wiki/Smappee
Last edited by simonrg on Saturday 07 April 2018 14:22, edited 1 time in total.
Raspberry Pi 2 B - 2A@5V PSU - Raspbian + Domoticz + RFXtrx(89), LightwaveRF House(dimmers, sockets, wireless/mood switches), Owl CM113, 4 LaCross Temp / Humidity Sensors, 4 Siemens PIR, Smappee, Solaredge, ESP8266
User avatar
Egregius
Posts: 2589
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Smappee

Post by Egregius »

@simonrg
If you remove the code block the link will be clickable.
simonrg
Posts: 329
Joined: Tuesday 16 July 2013 22:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8807
Location: North East England
Contact:

Re: Smappee

Post 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.
Raspberry Pi 2 B - 2A@5V PSU - Raspbian + Domoticz + RFXtrx(89), LightwaveRF House(dimmers, sockets, wireless/mood switches), Owl CM113, 4 LaCross Temp / Humidity Sensors, 4 Siemens PIR, Smappee, Solaredge, ESP8266
matteos1
Posts: 36
Joined: Monday 08 May 2017 17:29
Target OS: -
Domoticz version:
Contact:

Re: Smappee

Post 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 192 times
MQTT broker configuration on Smappee Plus Pro (1).pdf
(190.71 KiB) Downloaded 136 times
if someone can create script to control plug with mqtt system
thank a lot
Attachments
MQTT broker configuration on Smappee Plus Pro (1).pdf
(190.71 KiB) Downloaded 84 times
simonrg
Posts: 329
Joined: Tuesday 16 July 2013 22:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8807
Location: North East England
Contact:

Re: Smappee

Post 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
Raspberry Pi 2 B - 2A@5V PSU - Raspbian + Domoticz + RFXtrx(89), LightwaveRF House(dimmers, sockets, wireless/mood switches), Owl CM113, 4 LaCross Temp / Humidity Sensors, 4 Siemens PIR, Smappee, Solaredge, ESP8266
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest