RGB lamp change on weather condition next day. Cloudy and Partlycloudy

Hi!

I want to change a RGB lam color depending on weather condition next day. I have made templates for each weather condition i want the lamp to change on. I use the sensor in automation.

Its working but i have one problem.

The sensor “delvis_molnigt” and “molnigt” is both turned on when the weather is “cloudy” and “partlycloudy”…

My tought is that its turned on because the letters “cloudy” is in both sensors!!

How do i fix that?

Here is the sensors:

soligt:
friendly_name: “soligt imorgon”
value_template: “{{ ‘sunny’ in state_attr(‘weather.smhi_home’,‘forecast’)[1].condition }}”
snow:
friendly_name: “snow imorgon”
value_template: “{{ ‘snowy’ in state_attr(‘weather.smhi_home’,‘forecast’)[1].condition }}”
regn:
friendly_name: “regn imorgon”
value_template: “{{ ‘rainy’ in state_attr(‘weather.smhi_home’,‘forecast’)[1].condition }}”
delvis_molnigt:
friendly_name: “delvis imorgon”
value_template: “{{ ‘partlycloudy’ in state_attr(‘weather.smhi_home’,‘forecast’)[1].condition }}”
cloudy:
friendly_name: “molnigt imorgon”
value_template: “{{ ‘cloudy’ in state_attr(‘weather.smhi_home’,‘forecast’)[1].condition }}”

Use regex to limit the search.

value_template: “{{ state_attr(‘weather.smhi_home’,‘forecast’)[1].condition | regex_search("^cloudy$") }}”

This means the string has to start and end with cloudy, thus be false if it’s partlycloudy

Thx Hellis81 but i get this error:

Error loading /config/configuration.yaml: while parsing a block mapping
in “/config/binary_sensor.yaml”, line 30, column 9
expected , but found ‘’
in “/config/binary_sensor.yaml”, line 31, column 113

I don’t know what line 30 is.
Post your config and this time use the code format.

It worked when i deleted the double quotes:

value_template: “{{ state_attr(‘weather.smhi_home’,‘forecast’)[1].condition | regex_search( :slightly_smiling_face:^cloudy$ :slightly_smiling_face:) }}”

:slightly_smiling_face: = "

and replaced them with:

value_template: “{{ state_attr(‘weather.smhi_home’,‘forecast’)[1].condition | regex_search (’^cloudy$’) }}”

Thanks for the help anyway: Hellis81