Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Usage:
- - platform: command_line
- name: foo
- command: "php -f /home/homeassistant/vzapi.php 1"
- unit_of_measurement: "W"
- Todo:
- - Rewrite in Python
- - Use UUID instead of ID
- */
- if($argc != 2) die('id?');
- $sensor = (int)$argv[1];
- error_reporting(E_ALL);
- $mysql_serv = 'localhost';
- $mysql_user = 'vz-read';
- $mysql_pass = '*****';
- $mysql_datb = 'volkszaehler';
- $sql = new mysqli($mysql_serv, $mysql_user, $mysql_pass, $mysql_datb);
- //Yes, I know this can be used for SQL injections.
- $data = $sql->query("SELECT * FROM `data` WHERE `channel_id` = ".$sensor." ORDER BY `timestamp` DESC LIMIT 1 ");
- if($data->num_rows != 1) die();
- $data = $data->fetch_object();
- if($data->timestamp/1000 <= time()-300) die();
- echo $data->value;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement