Can I change states within/from customize.yaml

hey guys,

Newby here,

I installed a component predicting the precipitation.

Buienalarm custom_component for Home-Assistant

sensor:
  - platform: buienalarm
    timeframe: 15
    name: buienalarm
    monitored_conditions:
      - temperature
      - precipitation
      - precipitation_forecast_average
      - precipitation_forecast_total
      - next_rain_forecast

but the next_rain_forecast entity is only outputting:

-1	that is : No rain forecast withing timeframe
0 		that is : It is currently raining
N		that is : Rain is forecast within N minutes

and the default unit_of_measurement is minutes

so the outcome is one of the following:
next_rain_forecast -1 minutes
next_rain_forecast 0 minues
next_rain_forecast N minutes

in my opinion ugly as h.ll

I want a simple string as output aka state:
State -1: “It is dry”
State 0: “It is Raining”
State >0: “It will be raining within " & state & " minutes”

so fork it and rewrite the sensor.py file, or try to change the state value by
changing it in Home Assistant.

I chose the latter, but man what a pain is yaml, I thought I could write an entry in customize.yaml,
add a few if then statements and be done with it. Two days later still errors…

This is my attempt: (in customize.yaml)

sensor.buienalarm_next_rain_forecast:
  unit_of_measurement: false         #dont need units it will be plain strings
  friendly_name: Vooruitzicht		#Dutch for prospect

tried the following if then else approaches:

{% set count = states(sensor.buienalarm_next_rain_forecast) | int %}
{% if count == -1 %}
{% set state = 'It is dry' %}
{% endif %}"

Error:
missed comma between flow collection entries at line x, column 2:
{% set count = states(sensor.buie …
^
ok something about quotes according to google:
so retry

"{% set count = states(sensor.buienalarm_next_rain_forecast) | int %}"
"{% if count == -1 %}"
"{% set state = 'It is dry' %}"
"{% endif %}"

Nop still doesnt do it:
Error:
can not read an implicit mapping pair; a colon is missed at line x, column 69:
… larm_next_rain_forecast)|int %}"
^
new approach

condition:
    - condition: template
      value_template: "{% is_state('sensor.buienalarm_next_rain_forecast', -1) %}"

And just as you think you got something, bang ERROR extra keys not allowed @ data[‘customize’][‘condition’]

I tried most of the solutions found on google but I give up… anyone…???

Regards Frank

No.

You want to create a template sensor. This is where you would use the templates you have written. Configure the buienalarm sensor as specified in it’s documentation. Then create a template sensor to alter the state, name, icon etc. as necessary. Use this template sensor in place of the original sensor your front end.

Ok thank you, will give it a try…

Just by coincidence I ran into this topic. The sensor next_rain_forecast reports back the amount of minutes until next rainfall. That can be a negative number in case it is currently raining. That negative number is not limited to -1.
Which is kinda strange, so you should simply ignore all negative numbers here and then you’re good.