Template works in Dev Tools but fails in Honeycomb menu service call

Hey awesome people…

I am adding honeycomb menu (github) and have a button with the following action that is returning an error.

  buttons:
    - icon: mdi:radiator
      color_type: card
      color: var(--my-lounge-color)
      tap_action:
        action: call-service
        service: climate.set_temperature
        service_data:
          temperature: >
            {{ (state_attr('climate.lounge', 'temperature') |
            float | round(0)) + 1 }}
          entity_id: climate.lounge

This returns the following error:

event_type: call_service
data:
  domain: system_log
  service: write
  service_data:
    logger: frontend.js.latest.202401040
    message: |-
      Unhandled promise rejection from Edge 120.0.0.0 on Windows 10
      {
        "code": "invalid_format",
        "message": "expected float for dictionary value @ data['temperature']"
      }
    level: debug
origin: LOCAL
time_fired: "2024-01-23T17:29:37.380985+00:00"
context:
  id: 01HMVNXMB4W1PPKM6KQKF1XZA4
  parent_id: null
  user_id: 9e6ae3eef2074f80ac8df214b6bd51ce

But when I check the template in the Developer Tools it works…

{{ (state_attr('climate.lounge', 'temperature') | float | round(0)) + 1 }}

image

I can’t work out what’s causing the issue. Is there a way to see the actual service call including the data that is sent when the button is pressed, to see how it looks? Can anyone spot what the issue might be? It’s been puzzling me for days and there isn’t much to go on searching for Honeycomb menu.

Thanks v much,

Matt

Templates don’t work in the frontend unless the card supports it. Make a script that contains the action with the template and call that instead.

script that adjusts any climate by an offset

adjust_climate_temperature:
  fields:
    climate:
      description: The climate entity
      example: climate.lounge
      selector:
        entity:
          domain: climate
    offset:
      description: The temperature offset
      example: -1
      selector:
        number:
          min: -20
          max: 20
 
  sequence:
  - service: climate.set_temperature
    data:
      temperature: >
        {{ (state_attr(climate, 'temperature') + offset) | round(0) }}
    target:
      entity_id: "{{ climate }}"

card

  buttons:
    - icon: mdi:radiator
      color_type: card
      color: var(--my-lounge-color)
      tap_action:
        action: call-service
        service: script.adjust_climate_temperature
        service_data:
          climate: climate.lounge
          offset: 1

ah, thanks @petro, I’ll try that.

Incidentally (and to satisfy my curiosity), I just thought I’d try using javascript (I’m no expert but it’s used in some of my custom cards) and tried this and it works…

  tap_action:
    action: call-service
    service: climate.set_temperature
    data:
      temperature: |
        [[[ 
          return states['climate.lounge'].attributes.temperature + 1; 
        ]]]
      entity_id: climate.lounge

but it also logs this…

data:
  domain: system_log
  service: write
  service_data:
    logger: frontend.js.latest.202401040
    message: >-
      Unhandled promise rejection from Edge 120.0.0.0 on Windows 10

      HoneyCombJSTemplateError: ReferenceError: state_attr is not defined in
      'return `${state_attr['climate.lounge'].temperature}`'

      eval (/hacsfiles/honeycomb-menu/honeycomb-menu.js:24:1757)

      /hacsfiles/honeycomb-menu/honeycomb-menu.js:24:1834

      ct (/hacsfiles/honeycomb-menu/honeycomb-menu.js:24:2027)

      /hacsfiles/honeycomb-menu/honeycomb-menu.js:24:1626

      ct (/hacsfiles/honeycomb-menu/honeycomb-menu.js:24:1609)

      /hacsfiles/honeycomb-menu/honeycomb-menu.js:24:1626

      ct (/hacsfiles/honeycomb-menu/honeycomb-menu.js:24:1609)

      /hacsfiles/honeycomb-menu/honeycomb-menu.js:24:1626
    level: debug
origin: LOCAL

Unfortunately I’m not qualified to interpret this error, but I’m confused why the service call works despite the error. Is it an ‘acceptable’ error, if there is such a thing?

JS templates are only supported on a few custom cards. Your best option is the script.

Thank you, I will use the script (and tell my inquisitive brain to shut up)!

All you really need to understand here is that the frontend is the wild wild west with templates. A general rule is: You cannot use any template in any frontend card unless the documents mention that you can.

1 Like