Sian-Lee-SA / honeycomb-menu

Honeycomb menu is a Home Assistant module (not a card) that can be applied to any lovelace card. When activated by the defined action on said card, the module will display a 'rounded' list of honeycomb buttons with an optional XY pad to make interfacing with lovelace more fluent
Other
203 stars 11 forks source link

Issue with YXpad (can't use "y" variable) in Honeycomb Menu #69

Closed Scarpetta3 closed 1 month ago

Scarpetta3 commented 1 month ago

Hello, I was able to use all the features of this spectacular menu that you develop, I missed just one thing. I have tried a lot but it seems I can't figure out what I am missing. I am tying to make xypad work for my cover but I receive an error. I searched a lot in guides (for example this one: Link from which I substantially copy and paste the snippet of code for my service call on cover) and in your documentation but with no success.

This is my code for a nested Honeycomb Menu (if I put it on a non nested I have the same result):

tap_action:
  type: "custom:button-card"
  action: call-service
  service: honeycomb
  service_data:
    entity: cover.tapparella_camera_singola
    xy_pad:
      on_release: true
      y:
        # action: call-service
        service: cover.set_cover_position
        service_data:
          entity_id: cover.tapparella_camera_singola
          position: '{{  y }}'

The error I receive is the follow:

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

For now what I want to reach is to have a number from that "y" variable. The next step will be to return "100" for positive values and "0" for negative ones.

Thank You very much in advance

Regards Matteo

Sian-Lee-SA commented 1 month ago

Check the browser inspector and viewv the datav that is being sent through the webssocket when you make the xy_pad call

Scarpetta3 commented 1 month ago

Hello, I have found this two elements in the sent messages of the web socket.

FIRST ONE:

{type: "call_service", domain: "cover", service: "set_cover_position", return_response: false,…} domain : "cover" id : 62 return_response : false service : "set_cover_position" service_data : {entity_id: "cover.tapparella_camera_singola", position: "3.225"} entity_id : "cover.tapparella_camera_singola" position : "3.225" type : "call_service"

SECOND ONE:

{type: "call_service", domain: "system_log", service: "write", return_response: false,…} domain : "system_log" id : 63 return_response : false service : "write" service_data : {logger: "frontend.js.modern.202410024",…} level : "debug" logger : "frontend.js.modern.202410024" message : "Unhandled promise rejection from Chrome 130.0.0.0 on Windows 10\n{\n \"code\": \"invalid_format\",\n \"message\": \"expected int for dictionary value @ data['position']\"\n}" type : "call_service"

The only thing that I can notice is that is a double format.

Any suggestions? Can I do some other inspections?

Thank You Regards

Sian-Lee-SA commented 1 month ago

try position: '[[[ return parseInt( {{ y }} ) ]]]'... or Math.round() if you wish to round

Scarpetta3 commented 1 month ago

Ok, so probably we have found the first issue. But if I'll try to use the other template syntax '[[[ ]]]' it works only without the use of the passed variable {{ y }}. Infact this dumb snippet works:

position: '[[[if (5 > 0) {return 100;} else {return 0;}]]]'

It obviously return always 100 but it works. But this one, instead, broke the honeycomb menu that doesn't appear anymore:

position: '[[[if ({{ y }} > 0) {return 100;} else {return 0;}]]]'

Also this one doesn't work:

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

For the second issue, the only thing that I was concern about is the fact that this XYpad is inside a nested honeycomb menu (the button with the "icon cover", if pressed, open a second Honeycomb menu) and if u try to use the second templating syntax '[[[ ]]]' over there it broke the honeycomb Menu.

So I tryed to move the YXpad to the first Honeycomb Menu (not nested) and everything work smooth with this snippet code:

position: '[[[if ({{ y }} > 0) {return 100;} else {return 0;}]]]'

Does this have any sense for you?

Thank You very much again Regards

Sian-Lee-SA commented 1 month ago

What does console log show when the menu doesn't open?

Sian-Lee-SA commented 1 month ago

Also not sure why youy have

tap_action:
  type: "custom:button-card"

this is not valid for a tap_action

Scarpetta3 commented 1 month ago

Sorry for this:

tap_action: type: "custom:button-card"

I removed it but nothing change. Instead for the console output, here:

Uncaught (in promise) HoneyCombJSTemplateError: SyntaxError: Unexpected token '{' in 'if ({{ y }} > 0) {return 100;} else {return 0;}'
    at new Function (<anonymous>)
    at honeycomb-menu.js:24:1757
    at ct (honeycomb-menu.js:24:2027)
    at honeycomb-menu.js:24:1626
    at Array.forEach (<anonymous>)
    at ct (honeycomb-menu.js:24:1609)
    at honeycomb-menu.js:24:1626
    at Array.forEach (<anonymous>)
    at ct (honeycomb-menu.js:24:1609)
    at honeycomb-menu.js:24:1626

Thanks

Sian-Lee-SA commented 1 month ago

Give latest release a try, also remember to clear and hard refresh when updating js files

Scarpetta3 commented 1 month ago

I have tryed like you suggest the latest release that you push few hours ago. Everything works now, also in nested honeycomb Menu. I will test deep tomorrow cause here it's late but I can't see why it has to fail now.

Glad to see it was not completely my fault about that. I was very frustating about that.

Thank You very much for the support and for the substantially immediate fix for the issue.

Regards Matteo