Trying to make my Unifi Doorbell’s WDR settings following light intensity and therefore made below automation with template.
The developer of the Unifi Protect integration added the service on my request and unfortunately isn’t working as expected. The developer can’t find anything in his code what the error is causing and so he’s thinking about a general fault in my template or bug in the HA templating code.
Here’s my desired automation and below in the Github link there are more thing we tried and not work;
- alias: set_doorbell_wdr
trigger:
- platform: state
entity_id: input_number.zonnepanelen_cloud_coverage
- platform: state
entity_id: sensor.period_of_day
action:
- service: unifiprotect.set_wdr_value
data:
entity_id: camera.voordeur_bel
value: >
{% set wdr = 0|int %}
{% if(states("sensor.period_of_day")|lower=='day') %}
{% if((states("sensor.liveproduction")|int>100 and states("sensor.clearsky_current")|int>100)) %}
{% if((states("input_number.pv_cloud_coverage")|int)<50) %}
{% set wdr = 2 %}
{% else %}
{% set wdr = 3 %}
{% endif %}
{% else %}
{% set wdr = 1 %}
{% endif %}
{% elif(states("sensor.period_of_day")|lower=='night') %}
{% set wdr = 0 %}
{% elif(states("sensor.period_of_day")|lower=='morning' or states("sensor.period_of_day")|lower=='dusk') %}
{% set wdr = 1 %}
{% else %}
{% set wdr = 1 %}
{% endif %}
{{wdr|int}}
The error from the logbook;
Logger: homeassistant.components.automation.set_doorbell_wdr
Source: components/automation/__init__.py:416
Integration: Automatisering ([documentation](https://www.home-assistant.io/integrations/automation), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+automation%22))
First occurred: 18:14:02 (4 occurrences)
Last logged: 18:27:06
Error while executing automation automation.set_doorbell_wdr: expected int for dictionary value @ data['value']
The Github issue where more examples are posted:
Hopefully somebody can point me in the right direction to solve this
If you put it all into the template editor, of course it will be a string. Put just the template into the template editor. I did, and it comes out as a number:
I reduced your template to 1 online, to prevent interfering chars/spaces/etc.
I know that I only have to put the template in the “template editor” and not the whole automation
Locally I changed the suggested code and my automation/template is working now!!
Asked the dev of the integration to look at your suggestion.
Could you maybe give some explanation on how your code it better then current code and how its fixing the issue?
How do you have legacy_templates set? If you set it to true then all templates will result in strings as they always used to do.
The code change allows the value parameter of the service call to automatically convert strings to a number. This way either "3" or 3 would work. This is the typical way to write a service schema.