Help with long state values (> 255 characters)

I have a template sensor which I use for a daily summary, it looks like this:

- platform: template
  sensors:
    daily_summary:
      friendly_name: "Daily Summary"
      value_template: >
       Good morning Steve! It will take you {{ states.sensor.time_to_work.attributes.duration_in_traffic }} to get to work.
       Today, the weather is {{ states('weather.dark_sky') }}, with a high of {{ states.weather.dark_sky.attributes.forecast|map(attribute='temperature')|max }}°C and a low of {{ states.weather.dark_sky.attributes.forecast|map(attribute='temperature')|min }}°C.
       It is {{ states.climate.heating.attributes.current_temperature }}°C inside the house.
       {% if (as_timestamp(strptime(states.sensor.bin_days.attributes.date, "%d/%m/%Y")) - as_timestamp(now())) < (60 * 60 * 12) %}
       Make sure you have put the {{ states.sensor.bin_days.attributes.bins }} out, it is about to be collected.
       {% endif %}
       {% if states.sensor.pay_day.attributes.daysRemaining == 0 %}It's payday, hooray!{% endif %}
       Have a great day.

My issue now is that it can be greater than 255 characters, and just changes to ‘unknown’ because of this. Is it possible to get around this? I want the summary to be stored somewhere so it can be reused by multiple notifications (HTML5 and TTS).

Is the 255 limit just for the main state? Can I store this in an attribute under this entity, and just have the displayed state as something shorter?

Any help would be appreciated, thanks.

why do you need to store it? why can’t you just use the above for each of your notifications? Unless you change this often and it makes authoring too much?
I have something very similar and I just repeated the message for each of my announcements:
It’s way longer than 255 chars, but it works…

Maybe you could use a service template which, depending on the trigger, sends the same message but to different notification platforms?

1 Like

It just seems messy having to maintain two templates, when it could just be defined once.

Thinking about it, could the template be stored in a secret? And then referenced in through that? That way it’s only defined in a single place. Or perhaps it could use YAMLs anchor/reference features?

Yep that works, and its a lot cleaner too:

daily_summary.yaml

Good morning Steve! It will take you {{ states.sensor.time_to_work.attributes.duration_in_traffic }} to get to work.
Today, the weather is {{ states('weather.dark_sky') }}, with a high of {{ states.weather.dark_sky.attributes.forecast|map(attribute='temperature')|max }}°C and a low of {{ states.weather.dark_sky.attributes.forecast|map(attribute='temperature')|min }}°C.
It is {{ states.climate.heating.attributes.current_temperature }}°C inside the house.
{% if (as_timestamp(strptime(states.sensor.bin_days.attributes.date, "%d/%m/%Y")) - as_timestamp(now())) < (60 * 60 * 12) %}
Make sure you have put the {{ states.sensor.bin_days.attributes.bins }} out, it is about to be collected.
{% endif %}
{% if states.sensor.pay_day.attributes.daysRemaining == 0 %}It's payday, hooray!{% endif %}
Have a great day.

scripts/notification.yaml

- service: notify.google_assistant_broadcast
  data_template:
    message: !include ../daily_summary.yaml
2 Likes

@lolouk44, just looking at your Dafang camera setup - how did you get this working? Custom firmware on the camera?

yes, custom firmware, check this repo:

Perfect, thanks