Templating help - Show remaining time in HH:MM of timer

Hi @vonagio @123 @petro
I`ve made this sensor to show the remaining time based of the choosen program. If the dishwasher is powered on the sensor will display the time remaining of the program if the dishwasher is powered off the sensor will display " : -:-- "
Here is the sensor:

- platform: template
    sensors:
      remaining_time:
        friendly_name: "Remaining Time"
        value_template: >
            {% if states('sensor.402110526515021364_bsh_common_option_remainingprogramtime') == 'unavailable' %}  -:--
            {% elif (as_timestamp(states('sensor.402110526515021364_bsh_common_option_remainingprogramtime'))) >0  %}
            {% set sec = as_timestamp(states('sensor.402110526515021364_bsh_common_option_remainingprogramtime'))-as_timestamp(now()) %}
            {%set hr = (sec / 3600) | int %}
            {%set min = sec / 60 - hr * 60%} 
            {% if hr > 0 and is_state('switch.402110526515021364_bsh_common_setting_powerstate', 'on' ) %}
              {{"%d:%02d" % (hr, min + 1)}}  
            {% elif sec | round(1, default=0) <0  %}  
              -:--
            {%elif is_state('switch.402110526515021364_bsh_common_setting_powerstate', 'on' )%}
              {{"%d:%02d" % (hr, min + 1)}}
            {%else%}
              -:--
            {% endif %}
            {% endif %}

Hope this will work also for you

Also see this