Ik heb een probleem met valideren van een condition. Ben al redelijk lang aan het testen en doen.
Betreft een custom component:
https://community.home-assistant.io/t/garbage-pickup-date-mijnafvalwijzer-nl-custom-component
met deze code van GitHub:
https://github.com/xirixiz/home-assistant-config
Nou heb ik als automation:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| - alias: 'Trash - One day before'
trigger:
- platform: time
hours: 8
minutes: 50
seconds: 0
condition:
- condition: or
conditions:
- condition: template
value_template: '{{- (now().strftime("%Y-%m-%d")) == (as_timestamp(strptime(states.sensor.trash_gft.state, "%Y-%m-%d")) - (1 * 86400 )) | timestamp_custom("%Y-%m-%d") -}}'
- condition: template
value_template: '{{- (now().strftime("%Y-%m-%d")) == (as_timestamp(strptime(states.sensor.trash_restafval.state, "%Y-%m-%d")) - (1 * 86400 )) | timestamp_custom("%Y-%m-%d") -}}'
action:
- service: notify.bericht_rik_mobiel
data_template:
message: >-
{% if (now().strftime("%Y-%m-%d")) == (as_timestamp(strptime(states.sensor.trash_gft.state, "%Y-%m-%d")) - (1 * 86400 )) | timestamp_custom("%Y-%m-%d") %}
Het is vandaag - {{ now().strftime("%Y-%m-%d") }}. De groene bak wordt geleegd op: {{ states.sensor.trash_gft.state }}!
{% endif %}
{% if (now().strftime("%Y-%m-%d")) == (as_timestamp(strptime(states.sensor.trash_restafval.state, "%Y-%m-%d")) - (1 * 86400 )) | timestamp_custom("%Y-%m-%d") %}
Het is vandaag - {{ now().strftime("%Y-%m-%d") }}. De grijze bak wordt geleegd op: {{ states.sensor.restafval.state }}!
{% endif %} |
Dan krijg ik onderstaande foutmelding:
Error during or-condition: unsupported operand type(s) for -: ‘NoneType’ and ‘int’
Ik snap er werkelijk waar niks meer van. Heb al meerdere conditions getest, en blijf foutmeldingen houden.
Reeds geteste conditions
code:
1
2
3
4
5
6
7
8
| condition:
- condition: template
value_template: '{{ now().strftime("%Y-%m-%d") == (as_timestamp(states.sensor.trash_plastic.state) - (24*3600)) | timestamp_custom("%Y-%m-%d") }}'
of
condition: template
value_template: '{{- (now().strftime("%Y-%m-%d")) == (as_timestamp(strptime(states.sensor.trash_gft.state, "%Y-%m-%d")) - (1 * 86400 )) | timestamp_custom("%Y-%m-%d") -}}' |
Dan krijg ik deze foutmelding:
Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File “/usr/lib/python3.6/site-packages/homeassistant/components/automation/init.py”, line 335, in async_trigger
if skip_condition or self._cond_func(variables):
File “/usr/lib/python3.6/site-packages/homeassistant/components/automation/init.py”, line 444, in if_action
return all(check(hass, variables) for check in checks)
File “/usr/lib/python3.6/site-packages/homeassistant/components/automation/init.py”, line 444, in
return all(check(hass, variables) for check in checks)
File “/usr/lib/python3.6/site-packages/homeassistant/helpers/condition.py”, line 317, in template_if
return async_template(hass, value_template, variables)
File “/usr/lib/python3.6/site-packages/homeassistant/helpers/condition.py”, line 299, in async_template
value = value_template.async_render(variables)
File “/usr/lib/python3.6/site-packages/homeassistant/helpers/template.py”, line 132, in async_render
return self._compiled.render(kwargs).strip()
File “/usr/lib/python3.6/site-packages/jinja2/asyncsupport.py”, line 76, in render
return original_render(self, *args, **kwargs)
File “/usr/lib/python3.6/site-packages/jinja2/environment.py”, line 1008, in render
return self.environment.handle_exception(exc_info, True)
File “/usr/lib/python3.6/site-packages/jinja2/environment.py”, line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File “/usr/lib/python3.6/site-packages/jinja2/_compat.py”, line 37, in reraise
raise value.with_traceback(tb)
File “”, line 1, in top-level template code
TypeError: unsupported operand type(s) for -: ‘NoneType’ and ‘int’
Ik draai via Hassio met de versie 0.68.1. De Notify gaat via telegram en dat werkt voor andere automations prima.