Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Doc enhancement] Powerfull ideas using eval() #123

Open
JavanXD opened this issue Mar 7, 2024 · 2 comments
Open

[Doc enhancement] Powerfull ideas using eval() #123

JavanXD opened this issue Mar 7, 2024 · 2 comments

Comments

@JavanXD
Copy link

JavanXD commented Mar 7, 2024

Problem description: sending an url takes much time to reload the page, a simple javascript event, would be very fast in navigating on the dashboard.

Use cases: For example I have one tab on my WallPanel showing the cameras, as soon someone rings my doorbell, or as soon as movement is detected by my camera, I want to trigger a wakeup event on the WallPanel as well as navigate to the Camera sub-page.

I tried to do this using something like:

curl --location --request POST 'http://192.168.178.78:2971/api/command' \
--header 'Content-Type: application/json;charset=UTF-8' \
--data-raw '{
    "eval": "document.querySelector("paper-tab[aria-label="Hauseingang"]").dispatchEvent(new MouseEvent("click", {shiftKey: true}));"                        
}';

As you run the webView.evaluateJavascript() method this is definitely a very powerful solution.

Anotter use case I had in mind, was when someone rings my doorbell I don't only want to play the doorbell alarm on the WallPanel speaker but also flash a red screen on the screen in case my WallPanel is muted (baby sleeping). Here I wanted to create a red box element and make it visible for a view seconds everything using simple pure javascript, but triggering it using eval().

@TheTimeWalker could you please provide more examples in the documentation as well as fix the timeout bug #50 related to the eval() command which currently blocks this poweruser enhancement.

Originally posted by @JavanXD in #26 (comment)

@JavanXD
Copy link
Author

JavanXD commented Mar 7, 2024

Some template you could provide in the wallpanel documentation:

wallpanel.yaml inside /packages/

rest_command:
  wallpanel_speak:
    url: !secret wallpanel_apipath
    method: POST
    headers:
      accept: 'application/json, text/html'
    payload: "{'speak': '{{ message }}'}"
    content_type:  'application/json; charset=utf-8'
  wallpanel_play_alarm:
    url: !secret wallpanel_apipath
    method: POST
    headers:
      accept: 'application/json, text/html'
    payload: '{"audio": "http://homeassistant.fritz.box:8123/local/images443/polizei.mp3"}'
    content_type:  'application/json; charset=utf-8'
  wallpanel_play_doorbell:
    url: !secret wallpanel_apipath
    method: POST
    headers:
      accept: 'application/json, text/html'
    payload: '{"audio": "http://homeassistant.fritz.box:8123/local/images443/doorbell.mp3"}'
    content_type: 'application/json; charset=utf-8'
  wallpanel_play_nothing:
    url: !secret wallpanel_apipath
    method: POST
    headers:
      accept: 'application/json, text/html'
    payload: '{"audio": ""}'
    content_type:  'application/json; charset=utf-8'
  wallpanel_wakeup:
    url: !secret wallpanel_apipath
    method: POST
    headers:
      accept: 'application/json, text/html'
    payload: '{"wake": true, "wakeTime": 60}'
    content_type:  'application/json; charset=utf-8'
  wallpanel_settings:
    url: !secret wallpanel_apipath
    method: POST
    headers:
      accept: 'application/json, text/html'
    payload: '{"settings": true}'
    content_type:  'application/json; charset=utf-8'
  wallpanel_door:
    url: !secret wallpanel_apipath
    method: POST
    headers:
      accept: 'application/json, text/html'
    payload: '{"url": "http://homeassistant.fritz.box:8123/my-wallpanel/door"}'
    content_type:  'application/json; charset=utf-8'

@aeozyalcin
Copy link

If anyone stumbles on this post, here is how I managed to achieve navigating between HA dashboards without reloading the whole page (I'm using MQTT, this should also apply to HTTP API):

action: mqtt.publish
data:
  topic: wallpanel/mywallpanel/command
  payload: >-
    {"eval": "window.history.pushState(null,'','/url/to/other_dashboard');
    window.dispatchEvent(new CustomEvent('location-changed'));"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants