house-of-abbey / GarminHomeAssistant

Garmin application to provide a dashboard to control your Home Assistant
https://community.home-assistant.io/t/home-assistant-app-for-garmin/637348
MIT License
70 stars 12 forks source link

Question: why changing volume is not working? #133

Closed jose1711 closed 4 months ago

jose1711 commented 4 months ago

My item definition is as follows:

    {
     "name": "Volume -",
     "type": "template",
     "entity": "media_player.ht_a5000",
     "content": "{{ '.🔈.🔉.🔊.🕱'[:int(state_attr('media_player.ht_a5000', 'volume_level') * 40)] }}",
     "tap_action": {
      "service": "media_player.volume_set",
      "data": {
       "volume_level": "{{ state_attr('media_player.ht_a5000', 'volume_level') - 0.05 }}"
      }
     }
    }

This is modeled after https://community.home-assistant.io/t/media-player-volume-up-steps/17677/7 and I can confirm that the following YAML works in developer tool - service call:

service: media_player.volume_set
target:
  entity_id: media_player.ht_a5000
data:
  volume_level: "{{ state_attr('media_player.ht_a5000', 'volume_level') - 0.05 }}"

The problem is that Garmin HA reports an issue that no JSON has returned from an HTTP request. While I could write a wrapper script I would like to understand why this is not working out of the box. Thanks!

Nasimovy commented 4 months ago

have you tested or checked your JSON with the online checker? https://house-of-abbey.github.io/GarminHomeAssistant/web/

jose1711 commented 4 months ago

have you tested or checked your JSON with the online checker? https://house-of-abbey.github.io/GarminHomeAssistant/web/

Thank you for a hint. The checker is saying:

Incorrect type. Expected "number".

It looks like it does not like the quotes around the rendered template result. But then the issue is that template values must be quoted - no idea how to make it happy.

Nasimovy commented 4 months ago

it expects a number like it says. i think you cant use this :

  volume_level: "{{ state_attr('media_player.ht_a5000', 'volume_level') - 0.05 }}"

according to the examples you could set volume to say 50% by doing this:

  volume_level: 0.5

you could create 1 automation and 2buttons and call those buttons

jose1711 commented 4 months ago

As I am wrote in the original post, I know I can write a script for instance and put the logic there. But I did not want to hide it from menu json. Bottom line I guess is that template can only be used inside "content" tag.

philipabbey commented 4 months ago

@JosephAbbey Can you advise here please?

JosephAbbey commented 4 months ago
Incorrect type. Expected "number".

The execution for services in the app does not currently support templates, the editor reflects this.

You would need to create a script on ha for this to work.

It would not be a good option to add this feature as it would require multiple API calls for one action which would make it slow.