Hi,
I’ve some problems to call an API with “rest”. My API is from http://www.openkarotz.org/api/
I’m on HASSIO 5.9 and HA 2020.12.7
I use Developer Tools and my code is :
sensor:
- platform: rest
resource: http://192.168.2.205/cgi-bin/status
name: karotzetat
verify_ssl: 0
timeout: 20
value_template: "{{value_json.sleep}}"
The error is :
UndefinedError: 'value_json' is undefined
In the log I have :
2021-01-02 15:18:38 ERROR (Thread-478) [root] Uncaught thread exception
Traceback (most recent call last):
File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/usr/local/lib/python3.8/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 427, in _render_template
compiled.render(kwargs)
File "/usr/local/lib/python3.8/site-packages/jinja2/environment.py", line 1090, in render
self.environment.handle_exception()
File "/usr/local/lib/python3.8/site-packages/jinja2/environment.py", line 832, in handle_exception
reraise(*rewrite_traceback_stack(source=source))
File "/usr/local/lib/python3.8/site-packages/jinja2/_compat.py", line 28, in reraise
raise value.with_traceback(tb)
File "<template>", line 7, in top-level template code
File "/usr/local/lib/python3.8/site-packages/jinja2/sandbox.py", line 407, in getattr
value = getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'value_json' is undefined
If I call the api directly the result is :
{"version":"200","ears_disabled":"0","sleep":"0","sleep_time":"0","led_color":"ffff00","led_pulse":"1","tts_cache_size":"0","usb_free_space":"-1","karotz_free_space":"148.3M","eth_mac":"00:00:00:00:00:00","wlan_mac":"00:0E:8E:2C:93:D2","nb_tags":"0","nb_moods":"305","nb_sounds":"14","nb_stories":"0","karotz_percent_used_space":"37","usb_percent_used_space":"","data_dir":"/usr/openkarotz"}
I use some other functions with the same API and rest with no error like :
rest_command:
nabaztag_moods:
url: "http://{{ states('input_text.nabaztag_ip_address') }}/cgi-bin/apps/moods"
nabaztag_wakeup:
url: "http://{{ states('input_text.nabaztag_ip_address') }}/cgi-bin/wakeup?silent=1"
nabaztag_sleep:
url: "http://{{ states('input_text.nabaztag_ip_address') }}/cgi-bin/sleep"
nabaztag_ears_random:
url: "http://{{ states('input_text.nabaztag_ip_address') }}/cgi-bin/ears_random"
Do you have any idea ?
Thank for your help
François