sairon / esphome-nspanel-lovelace-ui

ESPHome component for NSPanel Lovelace UI
Other
126 stars 32 forks source link

[Question] How to pass new line in a service variable? #31

Open marek-vrana opened 1 year ago

marek-vrana commented 1 year ago

when I declare custom service in esphome like this:

- service: send_command
  variables:
    cmd: string
  then:
    - lambda: "id(nspanel).send_custom_command(cmd.c_str());"

I'm able to pass new line in description {{'\r\n'}}

service: esphome.nspanel_send_command
data:
  cmd: >-
    entityUpdateDetail~id~~65535~~3840~~61440~{{'\r\n'}}Description~52457~0~3~~52457

Now I'd like to define a new service, so that a new line can be included in the passed variable:

- service: notify_fullscreen
  variables:
    description: string
  then:
    - lambda: |-
          id(nspanel).send_custom_command("pageType~popupNotify");
          std::string cmd = "entityUpdateDetail~id~~65535~~3840~~61440~" + description + "~52457~0~3~~52457";
          id(nspanel).send_custom_command(cmd.c_str());

My idea is to call it like this:

service: esphome.nspanel_notify_fullscreen
data:
  description: "{{'\r\n'}}Description"

But that either ignores a new line or shows the escaped characters.

Can anyone help me out finding a proper syntax for it? Workarounds, e.g. replace with another string, are also appreciated. It's driving me nuts, can't figure it out.