Timestamp_custom getting the local time wrong

I think I’ve had this problem before, but I’ve got a template that seems to be getting the local time wrong. This is what I’ve got and right now it is outputting a time that is an hour longer than I expected.

          {% if states('sensor.sun_solar_elevation')|float <= -6 %}
            ILB in darkness conditions
          {% elif as_timestamp(states('sensor.sun_next_dusk'),0) < as_timestamp(now(),0)+2*3600 %}
            {{+ 'Dark within (h:m) ' ~ (as_timestamp(states('sensor.sun_next_dusk'),0) - as_timestamp(now(),0))|timestamp_custom("%H:%M",true)}}
          {% else %}
            {{"Light OK"}}
          {% endif %}

Change this:

timestamp_custom("%H:%M",true)

To this:

timestamp_custom("%H:%M",false)

Is it because I’m calculating the difference between 2 time zone aware entities, so the difference doesn’t need to use local time.

If you make the suggested change, does the template produce the correct value?

Because it does for me.

Yes it does, thank you. Just trying to understand hiw it works.

The result of the subtraction is a timestamp representing a UTC date and time. The second option in timestamp_custom determines how the supplied timestamp is interpreted (local or UTC).

Thanks. I understand now.

Another option is to dump the timestamps and not try to shoehorn date and time into a time difference:

{%- set dusk = states('sensor.sun_next_dusk') | as_datetime %}
{%- if states('sensor.sun_solar_elevation') | float(0) <= -6 %}
  ILB in darkness conditions
{%- elif dusk < now() + timedelta(hours=2) %}
  {%- set int_min = ((dusk - now()).total_seconds() // 60) | int %}
  Dark within (h:m) {{ int_min // 60 }}:{{ int_min % 60 }}
{%- else %}
  Light OK
{%- endif %}

Thanks, that is nice and clear.