Spot the error... nested template

yes please, unless you say Im being an idiot here, and need to make the Tuna sensor exact, instead of rounding up… Most importantly is they show the same in the frontend

replace this line in the TTS with this

{% set time = timestamp-now().replace(second=0).replace(microsecond=0).timestamp() %}
1 Like

Thanks , will do tonight and report back! Should give me time enough to try to understand why that makes the difference and juggle with the options.

See it coming I want the others to be exact too;-) and change accordingly. Will let you know what the outcome will be.

update

working perfectly! everything is spot on and reacts promptly. Cool.

Hi @petro

now things are working as they should, let me ask a more futile question.
In you templates you often use the dash after the {% sign:

  - platform: template
    sensors:
      next_alarm_timestamp:
        friendly_name: Next alarm timestamp
        entity_id:
          - sensor.time
          - input_boolean.alarmclock_wd_enabled
          - input_boolean.alarmclock_we_enabled
          - input_number.alarmclock_wd_hour
          - input_number.alarmclock_wd_minute
          - input_number.alarmclock_we_hour
          - input_number.alarmclock_we_minute
        value_template: >
          {%- macro getalarm(offsetday=0) %}
          {%- set day = (now().weekday() + offsetday) % 7 %}
          {%- set offset = offsetday * 86400 %}
          {%- set fmat = 'd' if day in range(5) else 'e' %}
          {%- set hour = 'input_number.alarmclock_w{}_hour'.format(fmat) %}
          {%- set minute = 'input_number.alarmclock_w{}_minute'.format(fmat) %}
          {%- set alarm = states(hour) | float | multiply(3600) + states(minute) | float | multiply(60) %}
          {%- set time = now().hour * 3600 + now().minute * 60 %}
          {{ (offset - time) + alarm if offsetday else alarm - time }}
          {%- endmacro %}
          
          {%- set weekday = is_state('input_boolean.alarmclock_wd_enabled','on') %}
          {%- set weekend = is_state('input_boolean.alarmclock_we_enabled','on') %}
          
          {%- set weekdays = [0,1,2,3,4] %}
          {%- set weekends = [5,6] %}
          {%- set day = now().weekday() %}
          {%- set nextday = day + 1 if day != 6 else 0 %}
          {%- if nextday in weekdays %}
            {%- if weekday %}
              {%- set offsetday = nextday %}
            {%- elif weekend %}
              {%- set offsetday = weekends[0] %}
            {%- else %}
              {%- set offsetday = None %}
            {%- endif %}
          {%- elif nextday in weekends %}
            {%- if weekend %}
              {%- set offsetday = nextday %}
            {%- elif weekday %}
              {%- set offsetday = weekdays[0] %}
            {%- else %}
              {%- set offsetday = None %}
            {%- endif %}
          {%- else %}
            {%- set offsetday = None %}
          {%- endif %}

Why is that? It doesn’t do anything does it? I know the - is for deleting whitespace in templates, but in the above template that is of no consequence.

In other templates we worked on there’s a mixed use of dashes, so Id like to ask if you’d agree they can be taken out everywhere except when whitespace should be managed?
thanks!

it makes a difference for macros and parsing the response from a macro.

Yes, I see that indeed in this sensor:

      next_alarm_text_new:
        friendly_name: Next alarm text new
        entity_id:
          - sensor.time
          - sensor.next_alarm_timestamp
          - sensor.next_alarm_new
          - sensor.next_alarm_day_new
        value_template: >
          {% set timestamp = states('sensor.next_alarm_timestamp') | int %}
          {%- macro pluralize(value, phrase) %}
          {%- set end = 's' if value > 1 else '' %}
          {{- '{} {}{}'.format(value, phrase, end) if value > 0 else '' }}
          {%- endmacro %}
<snip>

all other dashes in the package seem without effect.