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

Newline on Template Sensors #115

Closed
riyuk opened this issue Nov 25, 2022 · 4 comments · Fixed by #168
Closed

Newline on Template Sensors #115

riyuk opened this issue Nov 25, 2022 · 4 comments · Fixed by #168
Assignees
Labels
enhancement New feature or request T-Shirt-Size: S

Comments

@riyuk
Copy link

riyuk commented Nov 25, 2022

If you have a template sensor which has a newline in it {{- '\n' -}} the icon is still displaying everything in one line.
This actually is very useful if you want to display multiple sensor values in one button.

@cgiesche
Copy link
Owner

Hi,

the texts that are rendered to the button image are created as an SVG graphics. Allowing new-line characters to be parsed and converted into new text lines sounds easy but is a real pain. So unfortunatelly i will not support this in the near future :(

@riyuk
Copy link
Author

riyuk commented Jun 23, 2023

wouldnt something like that work? @cgiesche

// svgUtils.js
const text = (text, lineNr) => {
    if (text.indexOf("\n") > -1) {
        let lines = text.split("\n");
        for (let i = lineNr; i < (lines.length + lineNr); i++) {
            drawText(lines[i-lineNr], i);
        }
        return;
    }
    drawText(text, lineNr);
}

const drawText = (text, lineNr) => {
    this.snap.text(0, 26 + lineNr * 36, text)
        .attr(this.lineAttr)
        .transform(`translateX(${this.halfRes})`);
}

@riyuk
Copy link
Author

riyuk commented Jun 23, 2023

@cgiesche i can confirm that this works.
it was a mess to edit the compiled js but in the end it works. it would be great if you can do something like that. i can also do a pull request if you like.

btw a example on where to use it:
i have one button on stream deck which now displays the inside & outside temperature.
the sensor for that is a template sensor like that:

- name: streamdecktemperature
  state: "{{ states('sensor.aqara_outside_weather_temperature') | int }}° Outside{{- '\n' -}}{{ states('sensor.aqara_weather_temperature') | int }}° Inside"

@cgiesche
Copy link
Owner

cgiesche commented Jun 23, 2023

it was a mess to edit the compiled js

lul

wouldnt something like that work?

Ok, you are right. This seems to be easier than i expected. The painful experience of programming SVG in JavaScript has discouraged me :D

If you open a PR, i will accept it and build a prerelease. The official release to the store will take some time as it is a manual process including hand written mails to elgato. I always wait until enough changes have accumulated before asking Elgato to publish the plugin.

@cgiesche cgiesche reopened this Jun 23, 2023
@cgiesche cgiesche self-assigned this Jul 10, 2023
@cgiesche cgiesche added enhancement New feature or request T-Shirt-Size: S labels Jul 10, 2023
cgiesche added a commit that referenced this issue Jul 10, 2023
 fixed #139: UrlEncode whole text in SVG so no characters get lost or break the button.
@cgiesche cgiesche mentioned this issue Jul 10, 2023
cgiesche added a commit that referenced this issue Jul 10, 2023
fixed #139: UrlEncode whole text in SVG so no characters get lost or break the button.
cgiesche added a commit that referenced this issue Jul 10, 2023
closes #115: Added support for newline character in entity states.
fixed #139: UrlEncode whole text in SVG so no characters get lost or break the button.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request T-Shirt-Size: S
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants