Page 7 of 13

Re: fuTelldus - PHP application for sensor-logging

Posted: Fri Mar 17, 2023 9:45 am
by comaglove
Jesa wrote:
dumbo wrote:Would someone be so kind as to explain how to combine temperature and humidity in highcharts?
I have modified fuTelldus/inc/chart_highchart.php, and added some comments to show what changes I have done. There might be more changes than whats commented.

If one of the values is constant for the period selected there is no yAxis value (don't know how to fix this)

Hope this helps :-)

Jesa

Code: Select all

<script src="lib/packages/Highstock-1.3.1/js/highstock.js"></script>
<script src="lib/packages/Highstock-1.3.1/js/modules/exporting.js"></script>

<?php

	// Set how long back you want to pull data
    $showFromDate = time() - 86400 * $config['chart_max_days']; // 86400 => 24 hours * 10 days


    /* TEMP SENSOR 01: Get sensors
    --------------------------------------------------------------------------- */
    $query = "SELECT * FROM ".$db_prefix."sensors WHERE user_id='{$user['user_id']}' AND monitoring='1'";
    $result = $mysqli->query($query);

    while ($row = $result->fetch_array()) {

    	echo "<div class='well'>";

        unset($temp_values);
        $joinValues = "";
        unset($hum_values);		// added humidity variables
        $humValues = "";		// added humidity variables


        /* Get sensordata and generate graph
        --------------------------------------------------------------------------- */
        $queryS = "SELECT * FROM ".$db_prefix."sensors_log WHERE sensor_id='{$row["sensor_id"]}' AND time_updated > '$showFromDate' ORDER BY time_updated ASC";
        $resultS = $mysqli->query($queryS);

        
        while ($sensorData = $resultS->fetch_array()) {
            $db_tempValue = trim($sensorData["temp_value"]);
			$db_humValue = trim($sensorData["humidity_value"]);		//retrive humidity values

            $timeJS = $sensorData["time_updated"] * 1000;
            $temp_values[]        = "[" . $timeJS . "," . round($db_tempValue, 2) . "]";
			$hum_values[]         = "[" . $timeJS . "," . round($db_humValue, 2) . "]";		// do something with values
        }


        $joinValues = join($temp_values, ',');
        $joinhumValues = join($hum_values, ',');		// do something more with values


echo <<<end
<script type="text/javascript">

$(function() {
	$('#{$row["sensor_id"]}').highcharts('StockChart', {
		

		chart: { height: 600		// changed hight to make more space
		},

		title: {
            text: '{$row["name"]}'
        },

		rangeSelector: {
			enabled: true,
			buttons: [{
				type: 'hour',
				count: 1,
				text: '1h'
			},{
				type: 'hour',
				count: 12,
				text: '12h'
			},{
				type: 'day',
				count: 1,
				text: '1d'
			},{
				type: 'week',
				count: 1,
				text: '1w'
			}, {
				type: 'month',
				count: 1,
				text: '1m'
			}, {
				type: 'month',
				count: 6,
				text: '6m'
			}, {
				type: 'year',
				count: 1,
				text: '1y'
			}, {
				type: 'all',
				text: 'All'
			}],
			selected: 2
		},


        legend: {
			align: "center",
			layout: "horizontal",
			enabled: true,
			verticalAlign: "bottom",
		},

		yAxis: [{
			title: {
				text: 'Temperature (°C)',
			},
			labels: {
			    formatter: function() {
					return this.value + '\u00B0C';
			    },
				format: '{value}°C',
			    style: {
					color: '#777'
			    }
			},
			height: 260,			// set manual hight for temperature
		}, {
			title: {						// added humidity yAxis
				text: 'Humidity (%)',
				style: {color: '#31EBB3'}	// set manual color for yAxis humidity
			},
			labels: {						
			    formatter: function() {
					return this.value +'%';
			    },
				format: '{value}%',
			    style: {
					color: '#777'
			    }
			},
			top: 335,						//positioned humidity below temperature 
			height: 120,					// set manual hight for humidity
			offset: 0,						//lining humidity yAxis label upto temperature
		    
		}],

		series: [{
			name: 'Temperature',
			data: [$joinValues],
			type: 'spline',
			tooltip: {
				valueDecimals: 1, valueSuffix: '°C'
			}
		},{
			name: 'Humidity',				// added humidity as xAxis data
			data: [$joinhumValues],
			color: '#31EBB3',				// set graf color to the same as yAxis label
			type: 'spline',
			yAxis: 1,						// connecting humdity data to yAxis
			tooltip: {
				valueDecimals: 1, valueSuffix: '%'
			}
			
		}],

		// tooltip: {						// seperate tooltips set i data series
	    //    valueSuffix: '°C'
	    // },

		xAxis: {
			type: 'datetime',
		}, 

		 
	});
});

</script>

<div id="{$row["sensor_id"]}" style="height: 600px; min-width: 500px"></div>		
end;
	// changed height to match graf height

	echo "</div>";

    }

?>
Great, thanks!

Re: fuTelldus - PHP application for sensor-logging

Posted: Fri Mar 17, 2023 9:45 am
by Jesa
individual wrote:Regarding 0 for min temperature - Remotestick correctly shows min temperature somehow... Maybe there should be a workaround. Now I can confirm that even after days of using it, min temp is always displayed as 0.
It seems that when adding a new sensors there is made a record in the database where all values is registered with 0 as a value. This includes time_updated = 0. I'm guessing that this record is selected when you look at the rgraph. But of some strange reason it is not selected when looking at the public chart.

Work around:
Open phpAdmin and go into futelldus_sensors_log and run this sql query
SELECT * FROM `futelldus_sensors_log` WHERE time_updated = '0'

Delete these records and the graph should be good :-)

Remember to do this again if you add more sensors.

There is also one more difference from the public graph. The public graph shows max and min values for the selected period. The logged in rGraph shows all time high and low. If you want to change it add this " AND time_updated > '$showFromDate' " at then end of line 183 in fuTelldus\inc\chart_rgraph.php. The line should look like this:
$queryS = "SELECT AVG(temp_value), MAX(temp_value), MIN(temp_value), AVG(humidity_value), MAX(humidity_value), MIN(humidity_value) FROM ".$db_prefix."sensors_log WHERE sensor_id='$sensorID' AND time_updated > '$showFromDate'";

Jesa

Re: fuTelldus - PHP application for sensor-logging

Posted: Fri Mar 17, 2023 9:45 am
by HansMarius
Hvis jeg ønsker å benytte futelldus mot mssql server istedenfor mysql, hvilke filer må jeg da endre querys og statements i?

fuTelldus - PHP application for sensor-logging + Events

Posted: Fri Mar 17, 2023 9:45 am
by pain123
Hi, to begin with, I want to thank you for a very good Telldus UI! Have used it in a little more than a year and are very satisfied. Now, when I discovered that the "Events" is available, I have created a events.php page. It works fine and shows me the "Events" I added and some info about them. However, there is now the problem is coming! I can not possibly get the page to change the status of my events! I've checked how "Devices" is constructed and tried to do like as there but does not succeed. I've just added the ability to change if it is active or not, but you can certainly do much more. Is there anyone who can help me figure this out? Maybe dico wants to help and get a version 4 to hand out? :-)
Regards Andreas

Re: fuTelldus - PHP application for sensor-logging

Posted: Fri Mar 17, 2023 9:45 am
by hord
Jnsfi: Great look! Any chance you will to public with your files?
pain123: Good to hear about you progress! Maybe if you post your file, other eyes will have a look and possibly point us all in the correct direction...?

For my Hasta blends I wish to add features to fuTelldus where I can parameterize the total traveltime from top to bottom. This can then be used to put the blends to a certain open position with a button, by making fuTelldus send several commands in a row. (When I want window blends to 50% open, and total traveltime is 10sec, fuTelldus first send open command, wait 10sec, send close command, wait 5sec, send stop signal.) Hopefully other users with blends, fuTelldus and skills will publish a solution before I have figured out how to code this ; )

-Hord

Re: fuTelldus - PHP application for sensor-logging

Posted: Fri Mar 17, 2023 9:45 am
by pain123
What im looking for is how and what to send to telldus to activate and deactivate events for starters. To do that i must change active between 1 and 0 and all variabels must be sent from what i read in telldus API Explorer!
This is ajax_event_control.php:

Code: Select all

<?php
	
	require("lib/base.inc.php");
	require("lib/auth.php");


	/* Get parameters
	--------------------------------------------------------------------------- */
	if (isset($_GET['id'])) $getID = clean($_GET['id']);
	if (isset($_GET['description'])) $description = clean($_GET['description']);
	if (isset($_GET['minRepeatInterval'])) $minRepeatInterval = clean($_GET['minRepeatInterval']);
	if (isset($_GET['active'])) $active = clean($_GET['active']);
	if (isset($_GET['btnID'])) $btnID = clean($_GET['btnID']);




	/* Connect and send to telldus live
	--------------------------------------------------------------------------- */
	require_once 'HTTP/OAuth/Consumer.php';


	$consumer = new HTTP_OAuth_Consumer(constant('PUBLIC_KEY'), constant('PRIVATE_KEY'), constant('TOKEN'), constant('TOKEN_SECRET'));

	if ($state == "on") {
		$params = array('id'=> $getID,
					   'description'=> $description,
					   'minRepeatInterval'=> $minRepeatInterval,
					   'active'=> 1);
		$response = $consumer->sendRequest(constant('REQUEST_URI').'/event/setEvent', $params, 'GET');
	}

	if ($state == "off") {
		$params = array('id'=> $getID,
					   'description'=> $description,
					   'minRepeatInterval'=> $minRepeatInterval,
					   'active'=> 0);
		$response = $consumer->sendRequest(constant('REQUEST_URI').'/event/setEvent', $params, 'GET');
		
	}


	

?>
I have not found whether to use GET or POST or some detailed instructions on how to handle the Event
In futelldus_lights.js It stops at this line:

Code: Select all

ajaxRequest.open("GET", "ajax_event_control.php?state=" + state + "&id=" + eventID + "&description=" + description + "&minRepeatInterval=" + minRepeatInterval + "&active=" + active + "&&rand=" + Math.random()*9999, true);

Re: fuTelldus - PHP application for sensor-logging

Posted: Fri Mar 17, 2023 9:45 am
by pain123
Have finally managed to get a working Events page, where I to begin with can enable and disable my events! If you are interested then send a PM to know how to do!
:clap:
/A
pain123 wrote:What im looking for is how and what to send to telldus to activate and deactivate events for starters. To do that i must change active between 1 and 0 and all variabels must be sent from what i read in telldus API Explorer!
This is ajax_event_control.php:

Code: Select all

<?php
	
	require("lib/base.inc.php");
	require("lib/auth.php");


	/* Get parameters
	--------------------------------------------------------------------------- */
	if (isset($_GET['id'])) $getID = clean($_GET['id']);
	if (isset($_GET['description'])) $description = clean($_GET['description']);
	if (isset($_GET['minRepeatInterval'])) $minRepeatInterval = clean($_GET['minRepeatInterval']);
	if (isset($_GET['active'])) $active = clean($_GET['active']);
	if (isset($_GET['btnID'])) $btnID = clean($_GET['btnID']);




	/* Connect and send to telldus live
	--------------------------------------------------------------------------- */
	require_once 'HTTP/OAuth/Consumer.php';


	$consumer = new HTTP_OAuth_Consumer(constant('PUBLIC_KEY'), constant('PRIVATE_KEY'), constant('TOKEN'), constant('TOKEN_SECRET'));

	if ($state == "on") {
		$params = array('id'=> $getID,
					   'description'=> $description,
					   'minRepeatInterval'=> $minRepeatInterval,
					   'active'=> 1);
		$response = $consumer->sendRequest(constant('REQUEST_URI').'/event/setEvent', $params, 'GET');
	}

	if ($state == "off") {
		$params = array('id'=> $getID,
					   'description'=> $description,
					   'minRepeatInterval'=> $minRepeatInterval,
					   'active'=> 0);
		$response = $consumer->sendRequest(constant('REQUEST_URI').'/event/setEvent', $params, 'GET');
		
	}


	

?>
I have not found whether to use GET or POST or some detailed instructions on how to handle the Event
In futelldus_lights.js It stops at this line:

Code: Select all

ajaxRequest.open("GET", "ajax_event_control.php?state=" + state + "&id=" + eventID + "&description=" + description + "&minRepeatInterval=" + minRepeatInterval + "&active=" + active + "&&rand=" + Math.random()*9999, true);

Re: fuTelldus - PHP application for sensor-logging

Posted: Fri Mar 17, 2023 9:45 am
by jnsfi
Hord, sure! My project have been on hold for a while, so there are many unfinished pages (like config-page). I would be happy to make HTML-templates, if you or someone else would make back-end. Interested? :)

Re: fuTelldus - PHP application for sensor-logging

Posted: Fri Mar 17, 2023 9:45 am
by petzno
Thanks for what looks like a great application. I have just installed it and still not explored all the futures.

However I have one question. Since I for time being are doing some other web development I have all error reporting turned on in my server and the fuTelldus reports a lot of errors of type NOTICE which is due to undefined variables. Meaning that the files use variables without defining them. Is this something others have seen and/or being worked on?

I have temporary solved it by disabling error_reporting in the config.inc.php file.

Re: fuTelldus - PHP application for sensor-logging

Posted: Fri Mar 17, 2023 9:45 am
by petzno
Some more observations/questions:

1. Why is sensors and lights attached to a userid? This means that everytime I log in with a different user I have to sync the lists again. Makes it a little bit pointless to have more than one user.
2. Is it possible to combine all the graphs in highchart instead of the default? I noticed a combined highchart screenshot on the developer website so I guess it is possible.

Re: fuTelldus - PHP application for sensor-logging

Posted: Fri Mar 17, 2023 9:45 am
by arrow
feature request:

After spending allot of time trying to get a good and working monitor of energy-usage.

now I found that http://www.eliq.se have released a API that makes it possible to connect the same way.

is it possible to connect both to the telldus and Eliq ? and then monitor the energy and allsow trigger alarms.

if I make a request current value on this url
https://my.eliq.se/api/datanow?accessto ... XXXXXXXXXX
I get this reply:
{"createddate":"2014-01-24T12:31:59","power":7442.0}

if I ask on history
https://my.eliq.se/api/data?accesstoken ... XXXXXXXXXX
I get this:
{"startdate":"2014-01-24T00:00:00","enddate":"2014-01-24T01:00:00","intervaltype":"6min","data":[{"avgpower":2838.0,"energy":284.0,"temp_out":null,"time_start":"2014-01-24T00:00:00","time_end":"2014-01-24T00:06:00"},{"avgpower":2775.0,"energy":278.0,"temp_out":null,"time_start":"2014-01-24T00:06:00","time_end":"2014-01-24T00:12:00"},{"avgpower":2861.0,"energy":286.0,"temp_out":null,"time_start":"2014-01-24T00:12:00","time_end":"2014-01-24T00:18:00"},{"avgpower":2917.0,"energy":292.0,"temp_out":null,"time_start":"2014-01-24T00:18:00","time_end":"2014-01-24T00:24:00"},{"avgpower":2868.0,"energy":287.0,"temp_out":null,"time_start":"2014-01-24T00:24:00","time_end":"2014-01-24T00:30:00"},{"avgpower":2889.0,"energy":289.0,"temp_out":null,"time_start":"2014-01-24T00:30:00","time_end":"2014-01-24T00:36:00"},{"avgpower":5702.0,"energy":570.0,"temp_out":null,"time_start":"2014-01-24T00:36:00","time_end":"2014-01-24T00:42:00"},{"avgpower":7807.0,"energy":781.0,"temp_out":null,"time_start":"2014-01-24T00:42:00","time_end":"2014-01-24T00:48:00"},{"avgpower":4975.0,"energy":498.0,"temp_out":null,"time_start":"2014-01-24T00:48:00","time_end":"2014-01-24T00:54:00"},{"avgpower":4351.0,"energy":435.0,"temp_out":null,"time_start":"2014-01-24T00:54:00","time_end":"2014-01-24T01:00:00"}]}

so the question is how to get this in to the database and beeing graphed in a correct way

Re: fuTelldus - PHP application for sensor-logging

Posted: Fri Mar 17, 2023 9:45 am
by normannhaugland
I have tested your Application, but there is one problem. When I run the "Test Cron file > Run Schedule" everything Works fine, but when the cron job runs automatically nothing happens. If I require an email this give the following error code.

<br />
<b>Warning</b>: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent in <b>/home/nhtelsnp/public_html/app/telldus/lib/base.inc.php</b> on line <b>4</b><br /> <br />
<b>Warning</b>: session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent in <b>/home/nhtelsnp/public_html/app/telldus/lib/base.inc.php</b> on line <b>4</b><br />

Re: fuTelldus - PHP application for sensor-logging

Posted: Fri Mar 17, 2023 9:45 am
by Nautilus
Hi,

any idea why each time the cron_temp_log.php is run, it creates an empty file with the same name to \\SERVER\homes\username. Just found out that I had about 13 000 of them there already...:)

The server where I run it is Qnap Ts-259. Is it maybe because of this:
...I was able to overcome it by changing to wget instead of php so I just added the line to cron like "/usr/bin/wget -q http://<server>/Web/FuTelldus/cron_temp_log.php" and it works now
do I need something like >> /dev/null at the end?

Re: fuTelldus - PHP application for sensor-logging

Posted: Fri Mar 17, 2023 9:45 am
by turbosnute
Anyone doing any development on this project?

Re: fuTelldus - PHP application for sensor-logging

Posted: Fri Mar 17, 2023 9:45 am
by Furby
Does anyone know it it is possible to use Tellstick Duo + Raspberry Pi (running with tdtool) with fuTelldus? I have a Synology NAS and my feeling was that It should be fairly simple to have the Raspberry Pi export the sensor data to the NAS and then use fuTelldus to access the data. However, my skills when it comes to unix programming is limited... Any ideas?

//Furby