Ich versuche, bestimmte Daten von einer JSON-URL zu bekommen, aber ich bin stecken in, wie die Daten, die ich brauche. Die Ausgabe meiner url wie folgt aussieht:Json Info durch URL PHP
{
"dev_settings_device":{"uuid":"eneco-001-018946:hdrv_zwave_63523C6205B", "name":"settings_device", "internalAddress":"settings_device", "type":"settings_device", "supportsCrc":"49", "location":"(null)"},
"dev_10":{"uuid":"eneco-001-018946:hdrv_zwave_69423C65F08", "name":"HAE_METER_v2", "internalAddress":"10", "type":"HAE_METER_v2", "supportsCrc":"1", "supportedCC":"22 3c 3d 3e 56 60 70 72 7a 86 8b 73", "IsConnected":"1", "HealthValue":"10", "location":"(null)"},
"dev_10.1":{"uuid":"eneco-001-018946:hdrv_zwave_69448735F0E", "name":"HAE_METER_v2_1", "internalAddress":"10.1", "type":"gas", "supportsCrc":"0", "CurrentGasFlow":"0.00", "CurrentGasQuantity":"670.00", "location":"(null)"},
"dev_10.2":{"uuid":"eneco-001-018946:hdrv_zwave_6945CFF5F0E", "name":"HAE_METER_v2_2", "internalAddress":"10.2", "type":"elec", "supportsCrc":"0", "CurrentElectricityFlow":"428.00", "CurrentElectricityQuantity":"49464.00", "location":"(null)"},
"dev_10.3":{"uuid":"eneco-001-018946:hdrv_zwave_69458EC5F0E", "name":"HAE_METER_v2_3", "internalAddress":"10.3", "type":"elec_delivered_nt", "supportsCrc":"0", "CurrentElectricityFlow":"NaN", "CurrentElectricityQuantity":"NaN", "location":"(null)"},
"dev_10.4":{"uuid":"eneco-001-018946:hdrv_zwave_6947CCD5F0E", "name":"HAE_METER_v2_4", "internalAddress":"10.4", "type":"elec_received_nt", "supportsCrc":"0", "CurrentElectricityFlow":"NaN", "CurrentElectricityQuantity":"NaN", "location":"(null)"},
"dev_10.5":{"uuid":"eneco-001-018946:hdrv_zwave_694D7AB5F0E", "name":"HAE_METER_v2_5", "internalAddress":"10.5", "type":"elec_delivered_lt", "supportsCrc":"0", "CurrentElectricityFlow":"NaN", "CurrentElectricityQuantity":"NaN", "location":"(null)"},
"dev_10.6":{"uuid":"eneco-001-018946:hdrv_zwave_6941EFB5F0E", "name":"HAE_METER_v2_6", "internalAddress":"10.6", "type":"elec_received_lt", "supportsCrc":"0", "CurrentElectricityFlow":"NaN", "CurrentElectricityQuantity":"NaN", "location":"(null)"}
}
Meine Datei ähnliche Der Ausgang
<?php
error_reporting(E_ALL);
/* Written by Ierlandfan */
/* 1-11-2015 */
/* Version 1.1 */
/* Change ip_toon to the IP of your Toon */
/* start of current Energy usage import */
$file_string_gas = file_get_contents('http://192.168.1.66/hdrv_zwave?
action=getDevices.json');
$parsed_json = json_decode($file_string_gas, true);
var_dump($parsed_json['dev_10.1']);
/* Create new virtual sensor and write down the idx value */
/* Define idxvalue here */
$gasUsage=$parsed_json['CurrentGasQuantity'];
$idx = 933;
/* If this script is not run locally on the Domoticz server change 127.0.0.1
according to your Domoticz IP */
/* Send currentUsage to Domoticz */
$gasusage = curl_init("http://192.168.1.27:8080/json.htm?
type=command¶m=udevice&idx=$idx&nvalue=0&svalue=$gasUsage");
curl_exec($gasusage);
echo $gasUsage;
?>
sieht i aus dem var-Dump erhalten ist:
array(8) {
["uuid"]=>
string(39) "eneco-001-018946:hdrv_zwave_69448735F0E"
["name"]=>
string(14) "HAE_METER_v2_1"
["internalAddress"]=>
string(4) "10.1"
["type"]=>
string(3) "gas"
["supportsCrc"]=>
string(1) "0"
["CurrentGasFlow"]=>
string(4) "0.00"
["CurrentGasQuantity"]=>
string(6) "670.00"
["location"]=>
string(6) "(null)"
Der Fehler, den ich erhalten ist: PHP-Hinweis: Undefinierter Index: CurrentGasQuantity in /home/pi/domoticz/scripts/php/gas_data_json1.php in Zeile 16, aber für das Leben von mir verstehe ich nicht warum. Ich habe ein paar Dinge ausprobiert, aber es scheint, dass ich feststecke.
Dank wirkt wie ein Zauber. Sehr geschätzt! –