Problem with small template in service call

Hello,
I can’t figure out what I am doing wrong.
I am trying to use a simple service with this code:

action: call-service
service: cover.set_cover_position
service_data:
  entity_id: cover.tapparella_camera_singola
  position: >-
    {% if 5 > 0 %}
    100
    {% endif %}

I receive this error:

Failed to perform the action cover/set_cover_position. expected int for dictionary value @ data[‘position’]

If I put this on the Template tool on HA it tells me the output is a number so why do I receive this erro in which is written that he expect int

Thank You very much

You can’t use templates in card actions.

Hello,
I read the guide of your link and I undestand.
What I can’t understand is why in the page of the honeycomb menu (Link) the author talk about templating with the XYConfig:service_data

There are examples very similar of what I am trying to do but with the hue instead of the position.

Do you have any advice?

Regards
Matteo

What it uses is javascript templates, not jinja templates:

        hue: '[[[ return {{ y }} / 18 * {{ y_percentage }}; ]]]'   

If you want to use jinja templating, then what you could do is create a script with templates in it and call that script in the action, no templating needed in the front end.

If you’re using something non-standard like that, it would be helpful to say so in the original post…

Hello,
thnk you for your answer. I am trying my best and I swear I’ve tryed a lot and read, for what I was able to find, the documentation.
But till now I am struggle and stuck with this service call. I am able to use that JS but not able to use the parameters from the xypad.

If I write this:

position: '[[[ return 20; ]]]'

it works fine, but if I use this:

position: '[[[ return {{ y }} ]]]' 

even if in the docs say that will work, It doesn’t and the honeycomb menu doesn’t appear.
Instead if I use this:

position: '{{ y }}'

The honeycomb menu opens but this is the error that I receive:

Failed to perform the action cover/set_cover_position. expected int for dictionary value @ data[‘position’]

Thank you for support and for any advice or suggestion you can provide.

Regards
Matteo

The quote I showed was a part from the honeycomb docs, trying to show you it used javascript templates, not jinja ones. But I do not think you can get at the information you need from javascript.

What I mentioned below is how you solve it. Write a script with jinja templates to perform the action. then call the script from the action, so you do not need any kind of templating there.

Ok I will try that. But how can I pass the values of {{ y }} to the script?

Thank You

Oh, wait. I didn’t get from your post that y comes from the honeycomb integration. You could try an action to send a notification with the template as message to see what it evaluates to.

I really try my best but can’t find a way to make it work. I give up.
Thank you very much anyway for your support.

Regards
Matteo

Hello,
Luckily I didn’t give up and found the solution.
There was a problem in the Honeycomb menu module which, if the menu was nested, did not pass the XYpad parameters correctly. I reported and opened an issue in the repository and the developer, whom I thank, fixed the problem with a very quick release. Now even for nested menus it is possible to use the XYpad functionality and use the output with the two templating systems.

Thank you

1 Like