sounds like progress
Yeah, I’m not sure why that happened but it’s easy enough to change back when you know it’s all working.
sounds like progress
Yeah, I’m not sure why that happened but it’s easy enough to change back when you know it’s all working.
Morning,
With your fantastic assistance you have provided me with a solution.
In the end I put the motion sense capabilities on three cameras and it is evident that the first one must have a hardware issue. It works, but will only senses motion from a very close distance, even when set to high. The other two work seamlessly.
Thank you so very much for the rather drawn out solution.
@finity thanks for sharing your foscam motion detecting code. I am using hassio 0.115.3 and getting Indexerror: list index out of range on the regex_findall_index expression. The curl statement correctly pulls the device status string but the template fails on regex_findall_index. Any idea why this would be failing for me?
An help would be most appreciated.
Logger: homeassistant.components.sensor
Source: helpers/template.py:969
Integration: Sensor (documentation, issues)
First occurred: 12:00:06 PM (1 occurrences)
Last logged: 12:00:06 PM
command_line: Error on device update!
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 346, in _async_add_entity
await entity.async_device_update(warning=False)
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 471, in async_device_update
await self.hass.async_add_executor_job(self.update) # type: ignore
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/src/homeassistant/homeassistant/components/command_line/sensor.py", line 128, in update
self._state = self._value_template.render_with_possible_json_value(
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 323, in render_with_possible_json_value
return run_callback_threadsafe(
File "/usr/local/lib/python3.8/concurrent/futures/_base.py", line 439, in result
return self.__get_result()
File "/usr/local/lib/python3.8/concurrent/futures/_base.py", line 388, in __get_result
raise self._exception
File "/usr/src/homeassistant/homeassistant/util/async_.py", line 53, in run_callback
future.set_result(callback(*args))
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 355, in async_render_with_possible_json_value
return self._compiled.render(variables).strip()
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 1, in top-level template code
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 969, in regex_findall_index
return re.findall(find, value, flags)[index]
IndexError: list index out of range
Please post the sensor config and the output of the curl.
Also how are you testing the curl command? from your browser or from within HA?
HA needs to be able to get to the camera CGI data too. if not then the curl will fail internally to HA and I think that will cause what you are seeing.
The configuration.yaml was:
sensor:
- platform: command_line
command: curl -k --silent http://192.168.1.xxx:88/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=xxxxxxx&pwd=xxxxxxx
name: “Plaza Camera Motion”
scan_interval: 3
value_template: >
{% set status = value | regex_findall_index('Alarm>(\d+)</motion') %}
{% if status == "0" %}
Disabled
{%- elif status == "1" -%}
None
{%- elif status == "2" -%}
Detected
{% else %}
Not Determined
{%- endif -%}
Output from a cut and past of url into browser:
<CGI_Result>
<result>0</result>
<IOAlarm>0</IOAlarm>
<motionDetectAlarm>1</motionDetectAlarm>
<soundAlarm>1</soundAlarm>
<record>0</record>
<sdState>1</sdState>
<sdFreeSpace>109709920k</sdFreeSpace>
<sdTotalSpace>125126656k</sdTotalSpace>
<ntpState>1</ntpState>
<ddnsState>0</ddnsState>
<url></url>
<upnpState>0</upnpState>
<isWifiConnected>1</isWifiConnected>
<wifiConnectedAP>xxxx</wifiConnectedAP>
<infraLedState>0</infraLedState>
<humanDetectAlarmState>1</humanDetectAlarmState>
</CGI_Result>
Perhaps it has something to do with curl within docker as it fails on both hassio and a docker installaion on Raspbian.
I changed to “rest” and now it works fine:
- platform: rest
resource: http://192.168.1.xxx:88/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=xxxxxx&pwd=xxxxx
method: GET
name: “Plaza Camera Motion”
scan_interval: 3
value_template: >
{% set status = value | regex_findall_index('Alarm>(\d+)</motion') %}
{% if status == "0" %}
Disabled
{%- elif status == "1" -%}
None
{%- elif status == "2" -%}
Detected
{% else %}
Not Determined
{%- endif -%}
I don’t use hassio (now HassOS) but I use HA in Docker (Now HA Container). I think they operate similarly in this respect.
I had to set my system up so that I could run CLI commands from within my container on the host. Since then I haven’t had any issues. Good heads up on using REST instead of CLI tho. I never thought of using that instead.
Not a guru on Docker, but how do you allow it run CLI from a container?
Somewhere in recent upgrade, this has stopped working fro me as well.
I followed the basics of this procedure but with a few tweaks that I don’t reember right off the top of my head:
Thanks for the info, but after doing some additional trouble shooting I’m not sure that’s my problem.
I think there is an issue with the command_line platform. If I “docker exec -it [dockerid] bash” I can run the curl command no issue.
But when I attached to it to watch the logging, every time I try to execute my command_line command, I keep seeing “expr: syntax error”…the syntax is fine since it runs in a shell window.
Nothing has changed in my syntax, and had been working for several years, so something recently broke and I’m suspecting the command_line platform.
yeah, if it was working for yours before then the container/host thing isn’t the issue.
I doubt it’s the command_line integration tho since I’m on v115 and all of mine seem to be working and I haven’t made any changes except updating.