How concat strings in template?

Hi!

I want to add rest_command:

    rest_command:
      bedroom_tv_message:
        url: 'http://192.168.1.50:1080/cgi-bin/samygo-web-api.cgi?action=ALERT&type=CENTER&challenge={{ states.sensor.bedroom_tv_challenge.value }}&message={{ states.input_text.bedroom_tv_message.value }}'

But values in {{ }} is empty. What’s wrong?

Mainly the “value” is state, not value. :slight_smile: So at least it should be:

    rest_command:
      bedroom_tv_message:
        url: 'http://192.168.1.50:1080/cgi-bin/samygo-web-api.cgi?action=ALERT&type=CENTER&challenge={{ states.sensor.bedroom_tv_challenge.state }}&message={{ states.input_text.bedroom_tv_message.state }}'

But preferably you should use the states() function:

    rest_command:
      bedroom_tv_message:
        url: "http://192.168.1.50:1080/cgi-bin/samygo-web-api.cgi?action=ALERT&type=CENTER&challenge={{ states('sensor.bedroom_tv_challenge') }}&message={{ states('input_text.bedroom_tv_message') }}"
1 Like

Thanks seems like already try with states() with same result.
Should this work in sensor.template for value_template? I’m use this for testing template.

Today my microsd in RPi died :frowning: I will check your variant asap.

1 Like

The states() function does not return a different result if the state exists. It’s when the state does not exist that it matters. If you use states.x.y.state and there is no state for x.y then this will cause an error. But if you use states('x.y') then if the state doesn’t exist it will not cause an error but rather return ‘unknown’.

1 Like

Thanks. All works.

1 Like