rroller / dahua

Dahua Camera and Doorbell Home Assistant Integration
MIT License
382 stars 73 forks source link

'set_text_overlay' service does not allow Jinja2 templates / sensor values #274

Closed jrb80 closed 1 year ago

jrb80 commented 1 year ago

dahua.set_text_overlay service does not allow Jinja2 templates. For example;

tap_action:
  action: call-service
  service: dahua.set_custom_overlay
  target:
    entity_id:
      - camera.street_main
  data:
    group: 0
    text1: Cars {{ states('sensor.smart_motion_vehicle') }}
    text2: People {{ states('sensor.smart_motion_human') }}

When the automation/script is committed it nulls the template - example below

tap_action:
  action: call-service
  service: dahua.set_custom_overlay
  target:
    entity_id:
      - camera.street_main
  data:
    group: 0
    text1:  '[object Object]': null
    text2:  '[object Object]': null
name: Custom Overlay

The above Jinja2 template works correctly in the developer tools.

dahua.set_text_overlay service should be able to consume sensor data / templates for it to be useful. Using a static text string works but as mentioned, not very useful.

jgverweij commented 1 year ago

You need to put single-line templates between (double) quotes:

text1: "Cars {{ states('sensor.smart_motion_vehicle') }}"

jrb80 commented 1 year ago

You need to put single-line templates between (double) quotes: text1: "Cars {{ states('sensor.smart_motion_vehicle') }}"

That just converts the Jinja template into a static string and doesn't pull in the values (see image)

image

jgverweij commented 1 year ago

Thus the error is gone but the template it's processed :-( Strange to see '+' signs instead of spaces anyway.

Honestly I don't now whether a template is accepted for text1. Did try that via Developer tools?

But I think the problem is due to the service call in lovelace. See: https://community.home-assistant.io/t/how-to-use-service-template-with-tap-action/192638

jrb80 commented 1 year ago

But I think the problem is due to the service call in Lovelace. See: https://community.home-assistant.io/t/how-to-use-service-template-with-tap-action/192638

Thank you, that was the problem, the service call doesn't work from the Lovelace card. If I use the same method with an automation it works, weird. Clearly a bug with HA Lovelace cards.

Note, I had to insert underscores _ to get rid of the + that replaced the spaces. I think from Dahua is not accepting spaces.

rice1204 commented 5 months ago

just a related note, if you want to put in a space character, use %20