irrigation_unlimited
irrigation_unlimited copied to clipboard
Template support in service calls is highly valuable
It would be very useful to support the template processing in service calls:
For example, to support this template in a tap_action
of the card:
. . .
- icon: mdi:play
state_color: true
tap_action:
action: call-service
service: irrigation_unlimited.manual_run
service_data:
entity_id: binary_sensor.irrigation_unlimited_c1_z1
time: >
{# to increase currently running zone to 30 minutes #}
{%- set delta = 30 -%}
{%- set remaining = state_attr('binary_sensor.irrigation_unlimited_c1_z4', 'time_remaining') -%}
{%- if remaining -%}
{%- set time = strptime(remaining, "%H:%M:%S") + timedelta(minutes = delta) -%}
{{ '{:02d}:{:02d}:{:02d}'.format(time.hour, time.minute, time.second) }}'
{%- else -%}
{{ '00:{:02d}'.format(delta) }}'
{%- endif -%}
For the moment the validation of the 'time' attribute is not passed.
Agree, I assume the element is multiple-entity-row. This is really an issue for Ben regarding his work and to add this functionality.
I struck the same issue where I found some button entities do and others do not support templating. Very frustrating when attempting to do this sort of data manipulation. It eventually lead me to write a set of shims (helpers) in pyscript. You essentially encode what you want to do into some structure and pass it as the service_data parameter to the pyscript routine. Once inside pyscript the world is your oyster. Manipulate away and make the real service call.
I found the hard part here was when parameters change, as service do not accept extra params that they don't need.
Solved it by using button-card to wrap the card and use it javascript functions to return the proper object in the service data param.
Template support is now available.