For a long time I used variables from the addon hass-variables, but now I tried to use counters instead of variables because the variables stopped to work. I tried to replace the state check of variables by the state check of counters, but the following usage is wrong:
# - service_template: "{% if ((states('variable.counter_alarm_vorhof') | int) <= 10)\
# \ or ((states('variable.counter_alarm_vorhof') | int % 6) == 1) %}\n script.snapshot_telegram\n\
# {% else %}\n script.dummy_do_nothing\n{% endif %}\n"
# data:
# entity_id: camera.camera_vorhof
- service_template: "{% if ((states('counter.alarm_vorhof') | int) <= 10)\
\ or ((states('counter.alarm_vorhof') | int % 6) == 1) %}\n script.snapshot_telegram\n\
{% else %}\n script.dummy_do_nothing\n{% endif %}\n"
data:
entity_id: camera.camera_vorhof
it looks like this usage is wrong:
states('counter.alarm_vorhof')
I get this kind of errors:
TypeError: a bytes-like object is required, not 'NoneType'
2021-06-06 23:33:40 ERROR (MainThread) [homeassistant.components.automation.bewegung_kamera_vorhof] While executing automation automation.bewegung_kamera_vorhof
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/automation/__init__.py", line 504, in async_trigger
await self.action_script.async_run(
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1212, in async_run
await asyncio.shield(run.async_run())
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 348, in async_run
await self._async_step(log_exceptions=False)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 366, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/trace.py", line 249, in async_wrapper
await func(*args)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 692, in _async_repeat_step
await async_run_sequence(iteration, extra_msg)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 674, in async_run_sequence
await self._async_run_script(script)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 820, in _async_run_script
await self._async_run_long_action(
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 530, in _async_run_long_action
long_task.result()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1212, in async_run
await asyncio.shield(run.async_run())
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 348, in async_run
await self._async_step(log_exceptions=False)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 366, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 569, in _async_call_service_step
await self._async_run_long_action(service_task)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 530, in _async_run_long_action
long_task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1481, in async_call
task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1516, in _execute_service
await handler.job.target(service_call)
File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 278, in service_handler
await script_entity.async_turn_on(
File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 382, in async_turn_on
await coro
File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 404, in _async_run
return await self.script.async_run(variables, context)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1212, in async_run
await asyncio.shield(run.async_run())
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 857, in async_run
await super().async_run()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 348, in async_run
await self._async_step(log_exceptions=False)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 366, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 566, in _async_call_service_step
await service_task
File "/usr/src/homeassistant/homeassistant/core.py", line 1481, in async_call
task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1516, in _execute_service
await handler.job.target(service_call)
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
await self.hass.helpers.service.entity_service_call(
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 658, in entity_service_call
future.result() # pop exception if have
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 726, in async_request_call
await coro
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 695, in _handle_entity_call
await result
File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 639, in async_handle_snapshot_service
await hass.async_add_executor_job(_write_image, snapshot_file, image)
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/camera/__init__.py", line 636, in _write_image
img_file.write(image_data)
in the documentation I don’t get the idea how to get the count: