Multiply sensor value with another value

Hi Troon!

I’am back to you :slight_smile: maybe you remember for this script.
I wanna make more ‘if’ possibilities but can not solve it.

Something like this:

          forecast: >
            {% set forecast = states.weather.forecast_otthon.attributes.forecast %}
            {% set ns = namespace(fore_adj=[]) %}
            {% for item in forecast %}
              {% set owt, owtl = item['temperature'], item['templow'] %}
              {% set ns.fore_adj = ns.fore_adj + 
                                 [dict(item,
                                       **{'ow_temperature': owt,
                                          'ow_templow': owtl,
                                          'temperature': {% if owt > 5 owt*0.7 | round(0) %}
                                                         {% elif owt > 10 owt*0.8 | round(0) %}
                                                         {% elif owt > 15 owt*0.78 | round(0) %}
                                                         {% endif %}
                                          'templow': {% if owtl > 5 owtl*0.7 | round(0) %}
                                                     {% elif owtl > 10 owtl*0.8 | round(0) %}
                                                     {% elif owtl > 15 owtl*0.78 | round(0) %}
                                                     {% endif %}
            {% endfor %}
            {{ ns.fore_adj }}

Can you help me please?

That doesn’t work because you have nested one template inside another.

image

(and even if that were allowed, your {% if %} syntax is wrong, and you were only rounding your multiplier). Try something like this:

          forecast: >
            {% set forecast = states.weather.forecast_otthon.attributes.forecast %}
            {% set ns = namespace(fore_adj=[]) %}
            {% for item in forecast %}
              {% set owt, owtl = item['temperature'], item['templow'] %}
              {% set ns.fore_adj = ns.fore_adj + 
                                 [dict(item,
                                       **{'ow_temperature': owt,
                                          'ow_templow': owtl,
                                          'temperature': 
                                            (owt * 0.7)|round(0) if owt > 5 else (
                                              (owt * 0.8)|round(0) if owt > 10 else (
                                                (owt * 0.87)|round(0) if owt > 15 else (
                                                  owt
                                                )
                                              )
                                            )
                                          'templow':
                                            (owtl * 0.7)|round(0) if owtl > 5 else (
                                              (owtl * 0.8)|round(0) if owtl > 10 else (
                                                (owtl * 0.87)|round(0) if owtl > 15 else (
                                                  owtl
                                                )
                                              )
                                            )})] %}
            {% endfor %}
            {{ ns.fore_adj }}

The spacing isn’t required to be like that but makes it easier to see where the if / else statements line up, and I’ve added a default value which you were missing.

Thank you so much for your answare!

I don’t disappear just have some issue.
The sensor simply do not appear. Trying to find out alone what is the problem and write you.

There will be an error in your log, I’d imagine. It’s a very complex sensor declaration: I expect there’s a syntax error in there somewhere.

Thank you again for your help.
The solution was this: “It’s a very complex sensor declaration”. So i made two different sensor, one for tempereture an other for temp_low. And working.
I will not ask more help in this solution, thank you Troon!

1 Like