How to add text before return states

Hello,
How can I add text before “return states” ?
I have this code:

        label: |
          [[[ return states['sensor.xyz'].state + ' some text']]]

and it works, but I would like to add some text at the beggining, how can I do it ?

Greetings.

Solved, closing

Solved? How did you do it then?

Nice solution.

Probably by


label: |
          [[[ return 'xxxx' + states['sensor.xyz'].state + ' some text']]]

Probably not. I have tried everything. Infact I can not even get the added text after that was said to be working.

                label: |
#                  [[[ return states['input_number.timer_basement'].state ]]]
                  [[[ return states['input_number.timer_basement'].state + ' some text']]]

The top line with # works. The discussed line does not. I have seen the proper syntax before but can’t find it now.

You cannot use “#” inside strings.

Ofc it works:

For a label - you need to show it first by “show_label: true”:

OMG! :face_with_monocle: I had no idea! I use the # on all my development code so I can always revert to what works and make notes. You have no idea how much time I spent on That element…
image
By chance, do you know how I can return the state as a Integer?
Next I need to find a way of placing volume control, Up/Down in a media.player button.
Thank you again! 1 down, 99 to go LOL

What is a state’s value? Is it “5.0”?
Do you need to show it as “5”?

yes. My research says that any state is a string. and I don’t know the syntax to pipe it into a int.

Kind of “return parseInt(states[…].state)”

image

YeahYeah!!! Another command I was not aware of! It works!
I am just learning buttons… This one is just what I was hoping for.
Any idea of how to add volume controls to a media button? Currently my media buttons are just like the light and time WERE. Multiple buttons.

Suggest to create a separate thread for any unrelated questions to avoid mixing things.

Great idea. Thanks.
BTW, Your a great help.

1 Like