Hi,
I'm stuck!
Mijn JSON output:
Mijn Python code:
Mijn aanroep:
Mijn resultaat:
Het moet ergens zitten in:
Maar ik weet niet hoe ik het recht moet krijgen om de Lux uit te lezen?
I'm stuck!
Mijn JSON output:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
| { "ActTime" : 1596050682, "AstrTwilightEnd" : "00:27", "AstrTwilightStart" : "03:01", "CivTwilightEnd" : "22:11", "CivTwilightStart" : "05:17", "DayLength" : "15:32", "NautTwilightEnd" : "23:07", "NautTwilightStart" : "04:22", "ServerTime" : "2020-07-29 21:24:42", "SunAtSouth" : "13:44", "Sunrise" : "05:58", "Sunset" : "21:30", "app_version" : "2020.2", "result" : [ { "AddjMulti" : 1.0, "AddjMulti2" : 1.0, "AddjValue" : 0.0, "AddjValue2" : 0.0, "BatteryLevel" : 100, "CustomImage" : 0, "Data" : "0 Lux", "Description" : "", "Favorite" : 1, "HardwareID" : 7, "HardwareName" : "Zwave", "HardwareType" : "OpenZWave USB", "HardwareTypeVal" : 21, "HaveTimeout" : false, "ID" : "0000503", "LastUpdate" : "2020-07-29 21:24:40", "Name" : "Illuminance", "Notifications" : "false", "PlanID" : "0", "PlanIDs" : [ 0 ], "Protected" : false, "ShowNotifications" : true, "SignalLevel" : "-", "SubType" : "Lux", "Timers" : "false", "Type" : "Lux", "TypeImg" : "lux", "Unit" : 255, "Used" : 1, "XOffset" : "0", "YOffset" : "0", "idx" : "67" } ], "status" : "OK", "title" : "Devices" } |
Mijn Python code:
code:
1
2
3
4
5
6
7
8
9
10
11
| #Lux uitlezen def lux(): url = 'http://127.0.0.1/json.htm?type=devices&rid=\'67\'' print(url) response = requests.get(url) print(response) jsonData = json.loads(response.text) print(response.text) result = jsonData['result'][0][Data] print(result) return result; |
Mijn aanroep:
code:
1
| lux() |
Mijn resultaat:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
| http://127.0.0.1/json.htm?type=devices&rid='67' <Response [200]> { "ActTime" : 1596053015, "AstrTwilightEnd" : "00:27", "AstrTwilightStart" : "03:01", "CivTwilightEnd" : "22:11", "CivTwilightStart" : "05:17", "DayLength" : "15:32", "NautTwilightEnd" : "23:07", "NautTwilightStart" : "04:22", "ServerTime" : "2020-07-29 22:03:35", "SunAtSouth" : "13:44", "Sunrise" : "05:58", "Sunset" : "21:30", "app_version" : "2020.2", "status" : "OK", "title" : "Devices" } Traceback (most recent call last): File "ricky.py", line 108, in <module> lux() File "ricky.py", line 65, in lux result = jsonData['result'][0][Data] KeyError: 'result' |
Het moet ergens zitten in:
code:
1
| result = jsonData['result'][0][Data] |
Maar ik weet niet hoe ik het recht moet krijgen om de Lux uit te lezen?