Alright, here is an update to this…
I created another sensor in my currently working non-hassio HA in docker and strangely I get that same result.
Here is the sensor code:
- platform: command_line
command: 'curl -k --silent "http://192.168.1.56:8006/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=xxxx&pwd=yyyyy" '
name: "livingroom Camera Motion test"
And here is the resulting sensor which is in the same format as the one I thought was not working correctly:
I still don’t know why the returned value is different running the same command as a command_line sensor compared to running the exact same command in the console.
And the “grep” portion of the existing command_line sensor works with that command too.
here is that sensor that is working exactly as expected:
- platform: command_line
name: "Livingroom Camera Motion"
command: 'curl -k --silent "http://192.168.1.53:8003/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=xxxx&pwd=yyyy" | grep -oP "(?<=motionDetectAlarm>).*?(?=</motionDetectAlarm>)"'
value_template: >-
{%- if value == "0" -%}
Disabled
{%- elif value == "1" -%}
None
{%- elif value == "2" -%}
Detected
{%- endif -%}
scan_interval: 3
#friendly_name: 'Livingroom'
So, now I’m guessing it really is the way I’m setting up the regex_findall_index filter in the template that is causing the problem.
Here is the new non-working sensor:
- platform: command_line
command: 'curl -k --silent "http://192.168.1.56:8006/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=xxxx&pwd=yyyy" '
name: "livingroom Camera Motion test template"
value_template: >
{% set status = value | regex_findall_index('(.*)</motionDetectAlarm>') %}
{% if status == "0" %}
Disabled
{%- elif status == "1" -%}
None
{%- elif status == "2" -%}
Detected
{% else %}
Not Determined
{%- endif -%}
scan_interval: 3
and here is the error generated:
2019-08-14 14:09:34 ERROR (MainThread) [homeassistant.components.sensor] command_line: Error on device update!
Traceback (most recent call last):
File "/usr/src/app/homeassistant/helpers/entity_platform.py", line 291, in _async_add_entity
await entity.async_device_update(warning=False)
File "/usr/src/app/homeassistant/helpers/entity.py", line 419, in async_device_update
await self.hass.async_add_executor_job(self.update)
File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/src/app/homeassistant/components/command_line/sensor.py", line 126, in update
value, STATE_UNKNOWN
File "/usr/src/app/homeassistant/helpers/template.py", line 245, in render_with_possible_json_value
error_value,
File "/usr/local/lib/python3.7/concurrent/futures/_base.py", line 435, in result
return self.__get_result()
File "/usr/local/lib/python3.7/concurrent/futures/_base.py", line 384, in __get_result
raise self._exception
File "/usr/src/app/homeassistant/util/async_.py", line 208, in run_callback
future.set_result(callback(*args))
File "/usr/src/app/homeassistant/helpers/template.py", line 270, in async_render_with_possible_json_value
return self._compiled.render(variables).strip()
File "/usr/local/lib/python3.7/site-packages/jinja2/asyncsupport.py", line 76, in render
return original_render(self, *args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.7/site-packages/jinja2/_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "<template>", line 1, in top-level template code
File "/usr/src/app/homeassistant/helpers/template.py", line 820, in regex_findall_index
return re.findall(find, value, flags)[index]
IndexError: list index out of range
So i’ll tag @123 & @petro to see if they can shed some light on this confusion.
Please?