irrigation_unlimited icon indicating copy to clipboard operation
irrigation_unlimited copied to clipboard

Template support in service calls is highly valuable

Open DanyaFilatov opened this issue 2 years ago • 1 comments

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: Screenshot 2022-04-11 160359

    . . .
    - 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.

DanyaFilatov avatar Apr 11 '22 14:04 DanyaFilatov

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.

rgc99 avatar Apr 16 '22 01:04 rgc99

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.

luixal avatar Jun 12 '23 07:06 luixal

Template support is now available.

rgc99 avatar Jul 23 '23 05:07 rgc99