Move template from yaml to GUI

Hello,
Any idea how I can recreate following configuration.yaml template in the 'Create Helper" GUI:

template:

  • sensor:
    • name: “Electricity Rate”
      state: >
      {%- if is_state(‘binary_sensor.day_tariff’, ‘on’) -%}0.2931
      {%- else -%}0.17348
      {%- endif -%}
      unique_id: electricity_rate
      unit_of_measurement: BGN/kWh

Helpers > Template > Sensor

Then the template under state in your example goes in the field “State*”… and everything else goes in their matching fields, except unique_id which is not available in the UI.

It shows as unavailable:

Compare the code in your first post with that in your screenshot.

Hint: it looks like you’ve omitted the quotation marks around the binary sensor entity_id in the is_state function. This function won’t return a value without them, hence ‘unavailable’. You also need quotes around the state value: 'on'.

You’ve also changed the decimal separator from a point to a comma. Not sure if that is important for how you intend to use this sensor though.

1 Like

As Chris has pointed out above, you are missing quotes around the entity ID and state args in your is_state() function. Without those quotes Jinja interprets binary_sensor.day_tariff as a variable instead of a string, and you haven’t defined a value for that variable… which will cause an error. IIRC, on will be treated as a boolean, but the state arg expects a string, so that will cause a different error.

Hello,

You are both right, I removed the quote marks as there was warning for an error:

I’ve now typed them back in and there is no warning. It seems formatting issue with the originally copied string.

Thank you