espeasy sonoff pulse counter Metern
Re: espeasy sonoff pulse counter Metern
I have eliminated water meter / sensor, but Inputs and self-consumption are always at 0
Re: espeasy sonoff pulse counter Metern
I don't know what your trying to do
It's a new meter for water, it doesen't have anything with self-consumption.
Please don't assign a meter number to another one.
Maybe the virtual water counter haven't count yet.. You can type in CLI : "req_espeasy.php -prev" to see values.
If you need more help i'am ok to look at your logger, just pm me the adress and a temporary password.

Please don't assign a meter number to another one.
Maybe the virtual water counter haven't count yet.. You can type in CLI : "req_espeasy.php -prev" to see values.
If you need more help i'am ok to look at your logger, just pm me the adress and a temporary password.
Re: espeasy sonoff pulse counter Metern
when can i send you pm?
Re: espeasy sonoff pulse counter Metern
with command "req_espeasy -prev"
you get it
/dev/shm/req_espeasy.json: Array ([virt_tot] => 0 [esp_count] => 1132.5)
is not valid, the correct format is 6 (1234.5 * l)
I did not change the metern number
after copying your script
auroconsumption and inputs have become 0
you get it
/dev/shm/req_espeasy.json: Array ([virt_tot] => 0 [esp_count] => 1132.5)
is not valid, the correct format is 6 (1234.5 * l)
I did not change the metern number
after copying your script
auroconsumption and inputs have become 0
Re: espeasy sonoff pulse counter Metern
It's hard to debug like that. Did you set a passover value like 100000 ?
req_espeasy have nothing to do with autoconsumption
req_espeasy have nothing to do with autoconsumption

Re: espeasy sonoff pulse counter Metern
I set the value of 100000 to passover, now the value is visible, but always increases even if the counter is stopped.
if you want I send you ip address and password
if you want I send you ip address and password
Re: espeasy sonoff pulse counter Metern
ok, send me in pm a temp password.
-
- Posts: 97
- Joined: Tue Apr 14, 2015 9:25 am
Re: espeasy sonoff pulse counter Metern
Hi jeanmarc
it seams that on the new vesion of espeasy they modify the structure of json
now it's reported like this:
my task is number 3
and as you can see they reported:
total, count and time as "value"
so i think that should be modify a bit your php to recnize the value, right?
can you please have a look on it?
thanks so much!!!!!
it seams that on the new vesion of espeasy they modify the structure of json
now it's reported like this:
Code: Select all
System
Build 20102
Git Build "mega-20180927"
System libraries "ESP82xx Core 00000000, NONOS SDK 2.2.1(cfd48f3), LWIP: 2.0.3"
Plugins 74
Plugin description " [Normal] [Testing] [Development]"
Local time "2018-12-09 11:11:16"
Unit 204
Name "Sonoff_gas_204"
Uptime 753
Last boot cause "Cold boot"
Reset Reason "Power on"
Load 21.2
Load LC 10842
Free RAM 12664
WiFi
Hostname "Sonoff-gas-204-204"
IP config "Static"
IP "192.168.0.204"
Subnet Mask "255.255.255.0"
Gateway IP "192.168.0.1"
MAC address "80:7D:3A:6B:2D:EC"
DNS 1 "8.8.8.8"
DNS 2 "0.0.0.0"
SSID "VodafoneASUS"
BSSID "BC:15:AC:D3:90:24"
Channel 8
Connected msec 45180128
Last Disconnect Reason 1
Last Disconnect Reason str "(1) Unspecified"
Number reconnects 0
RSSI -69
nodes
0
nr 154
name "NODEMCU_154_MODIF"
build 20103
platform "ESP Easy Mega"
ip "192.168.0.154"
age 2
1
nr 196
name "sonoff_S20_pompa_196"
build 20102
platform "ESP Easy Mega"
ip "192.168.0.196"
age 1
2
nr 197
name "Sonoff_bagno_PT_197"
build 20102
platform "ESP Easy Mega"
ip "192.168.0.197"
age 1
3
nr 199
name "sonoff_bagno_mansarda_199"
build 20102
platform "ESP Easy Mega"
ip "192.168.0.199"
age 3
4
nr 200
name "Sonoff_200_VCM_mansarda"
build 20102
platform "ESP Easy Mega"
ip "192.168.0.200"
age 1
5
nr 201
name "sonoff_201_vcm_PT"
build 20102
platform "ESP Easy Mega"
ip "192.168.0.201"
age 1
6
nr 203
name "Presepe_esterno203"
build 20102
platform "ESP Easy Mega"
ip "192.168.0.203"
age 1
7
nr 204
name "Sonoff_gas_204"
build 20102
platform "ESP Easy Mega"
ip "192.168.0.204"
age 1
Sensors
0
TaskValues
0
ValueNumber 1
Name "Switch"
NrDecimals 0
Value 0
DataAcquisition
0
Controller 1
IDX 0
Enabled "false"
1
Controller 2
IDX 0
Enabled "false"
2
Controller 3
IDX 0
Enabled "false"
TaskInterval 0
Type "Switch input - Switch"
TaskName "Rele_sonoff"
TaskEnabled "true"
TaskNumber 1
1
TaskValues
0
ValueNumber 1
Name "Switch"
NrDecimals 0
Value 0
DataAcquisition
0
Controller 1
IDX 0
Enabled "false"
1
Controller 2
IDX 0
Enabled "false"
2
Controller 3
IDX 0
Enabled "false"
TaskInterval 0
Type "Switch input - Switch"
TaskName "sonoff_pulsante"
TaskEnabled "true"
TaskNumber 2
2
TaskValues
0
ValueNumber 1
Name "Count"
NrDecimals 2
Value 0
1
ValueNumber 2
Name "Total"
NrDecimals 2
Value 1
2
ValueNumber 3
Name "Time"
NrDecimals 2
Value 1587943
DataAcquisition
0
Controller 1
IDX 0
Enabled "false"
1
Controller 2
IDX 0
Enabled "false"
2
Controller 3
IDX 0
Enabled "false"
TaskInterval 1
Type "Generic - Pulse counter"
TaskName "gas"
TaskEnabled "true"
TaskNumber 3
TTL 1000
and as you can see they reported:
total, count and time as "value"
so i think that should be modify a bit your php to recnize the value, right?
can you please have a look on it?
thanks so much!!!!!
Re: espeasy sonoff pulse counter Metern
hi,
Could you give me the return of print_r(espjson) ?
Could you give me the return of print_r(espjson) ?
Code: Select all
#!/usr/bin/php
<?php
// A simple script to request a espeasy counter that doesn't always increase (after a surge) and make virtual meter.
// You should set your meter ID in meterN and define a non null pass over value (like 100000)
// chmod +x then ln -s /srv/http/comapps/req_espeasy.php /usr/bin/req_espeasy
// Use req_espeasy -total as main command -live as live command
// Config
$pathtomn = '/srv/http/metern'; // without / at the end
$metnum = 1; // Vitual meter number
$url = 'http://192.168.1.140/json?tasknr=2'; // espeasy url
// No edit should be needed bellow
if (isset($_SERVER['REMOTE_ADDR'])) {
die('Direct access not permitted');
}
if (isset($argv[2])) {
die("Abording: Too many arguments\n");
}
if (!isset($argv[1])) {
die("\nUsage: req_espeasy { total | live | Humidity | prev }\n
-total : Virtual total counter
-live : Counter live value
-Humidity : Show humidity value
-prev : Show previous file
\n");
}
// Save previous values in a file, make sure the http user can write there
$prevfile = '/dev/shm/req_espeasy.json';
if (file_exists($prevfile) && !is_writable($prevfile)) {
die("$prevfile not writable");
}
define('checkaccess', TRUE);
include("$pathtomn/config/config_main.php");
include("$pathtomn/config/memory.php");
include("$pathtomn/config/config_met$metnum.php");
function retrievecsv($meternum, $csvarray, $passo) // Retrieve last know value in csv
{
$datareturn = null;
$contalines = count($csvarray);
$j = 0;
while (!isset($datareturn)) {
$j++;
$array = preg_split('/,/', $csvarray[$contalines - $j]);
$datareturn = (int) trim($array[$meternum]);
if ($datareturn == '') {
$datareturn = null;
}
if ($j == $contalines) {
$datareturn = 0;
}
}
if ($datareturn > $passo) {
$datareturn -= $passo;
}
return $datareturn;
}
if ($argv[1] == '-live' || $argv[1] == '-total' || $argv[1] == '-Humidity') { // Get last values
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, 3000); // error
$espjson = array();
if (($espjson = curl_exec($ch)) === false) {
die(curl_error($ch) . "\n");
}
curl_close($ch);
/* testing
$espjson = '{
"TaskName": "counter",
"Count": 10.00,
"Total": 10,
"Time": 1487.00
}';*/
/*
$espjson ='{
"TaskValues": [
{"ValueNumber":1,
"Name":"Temperature",
"NrDecimals":2,
"Value":24.10
},
{"ValueNumber":2,
"Name":"Humidity",
"NrDecimals":2,
"Value":55.30
}],
"TTL":60000,
"DataAcquisition": [
{"Controller":1,
"IDX":21,
"Enabled":"true"
},
{"Controller":2,
"IDX":0,
"Enabled":"false"
},
{"Controller":3,
"IDX":0,
"Enabled":"false"
}],
"TaskInterval":60,
"Type":"Environment - DHT11/12/22 SONOFF2301/7021",
"TaskName":"dht22",
"TaskEnabled":"true",
"TaskNumber":2
}';
*/
$espjson = json_decode($espjson, true);
// Test :
print_r($espjson);
}
if ($argv[1] == '-live') {
if (!isset($espjson['Count'])) {
die("Abording: Cannot get live Count value\n");
}
$val = (float) $espjson['Count'];
$outstr = utf8_decode("${'LID' . $metnum}($val*${'LIVEUNIT' . $metnum})\n");
echo "$outstr";
} elseif ($argv[1] == '-total') {
if (!isset($espjson['Total'])) {
die("Abording: Cannot get last Total value\n");
}
// Retrieve previous virtual meter value
if (file_exists($prevfile)) {
$data = file_get_contents($prevfile);
$previous = json_decode($data, true);
} else {
$tdfile = date('Ymd');
$tdfile = $pathtomn . '/data/csv/' . $tdfile . '.csv';
$ytdfile = date('Ymd', strtotime("-1 day"));
$ytdfile = $pathtomn . '/data/csv/' . $ytdfile . '.csv';
if (file_exists($tdfile)) {
$lines = file($tdfile);
} else if (file_exists($ytdfile)) {
$lines = file($ytdfile);
}
if (file_exists($tdfile) || file_exists($ytdfile)) { // today or yesterday
$contalines = count($lines);
$previous['virt_tot'] = retrievecsv($metnum, $lines, ${'PASSO' . $metnum});
} else { // restarting from scratch !
$previous['virt_tot'] = 0;
}
$previous['esp_count'] = 0;
}
$last = (float) $espjson['Total'];
$prev = (float) $previous['esp_count'];
if ($last > $prev) {
$diff = $last - $prev; // Increment vitural meter
$previous['virt_tot'] += $diff;
if ($previous['virt_tot'] >= ${'PASSO' . $metnum}) { // passed over
$previous['virt_tot'] -= ${'PASSO' . $metnum};
}
$previous['esp_count'] = $espjson['Total'];
} elseif ($last < $prev) { // surge or esp counter restart
$previous['esp_count'] = 0;
}
// Saving previous values
$data = json_encode($previous);
file_put_contents($prevfile, $data);
$val = $previous['virt_tot'];
// Output
$outstr = utf8_decode("${'ID' . $metnum}($val*${'UNIT' . $metnum})\n");
echo "$outstr";
} elseif ($argv[1] == '-Humidity') {
$val = $espjson['TaskValues'][1]['Value'];
$outstr = utf8_decode("Humidity($val*hum)\n");
echo "$outstr";
} elseif ($argv[1] == '-prev') {
if (file_exists($prevfile)) {
echo "\n$prevfile :\n\n";
$data = file_get_contents($prevfile);
$previous = json_decode($data, true);
print_r($previous);
}
}
?>
-
- Posts: 97
- Joined: Tue Apr 14, 2015 9:25 am
Re: espeasy sonoff pulse counter Metern
hi, i'm not sure if i full fill your request, but, i simply copy paste your code over mine, sobstituite my IP(192.168.0.204) and my task(3) and my meter (20)
than from raspberry:
Code: Select all
pi@raspberrypi:~ $ req_espeasy -total
PHP Notice: Use of undefined constant espjson - assumed 'espjson' in /var/www/comapps/req_espeasy.php on line 115
espjsonAbording: Cannot get last Total value
Code: Select all
pi@raspberrypi:~ $ req_espeasy -live
PHP Notice: Use of undefined constant espjson - assumed 'espjson' in /var/www/comapps/req_espeasy.php on line 115
espjsonAbording: Cannot get live Count value
pi@raspberrypi:~ $
another thing, my Gas meter is now showing 1104,25m3
with your php there is no way to set a "starting point" of m3? in this case we can insert the previous value of gas meter.
Who is online
Users browsing this forum: No registered users and 0 guests