I know the state entity was modified to be limited to 255 characters and the work around was to use the input_text field.
But it appears that input_text is also limited.
Also you can set the max allowed; and if you set something over 255 no error is emitted but it certainly does fail when you try to populate it over 255 characters.
So how can I create a big-ass-string without custom components?
You can use the custom-card state_card-value_only.html, and have massive cards…
check and see my adaptation of it, to provide some more coloring options
You can create a python script. What are you trying to do with the big-ass-string? I may be able to help with a solution, but there are many. A direction might steer towards a solution.
you might be able to use this, not this has the custom-card commented out. depending on the amount of your lights, this might not need it.
Note 2, this creates a badge with a text.
##########################################################################################
# Lights:
# Badges images: /config/www/lights
# https://community.home-assistant.io/u/Mariusthvdb/
##########################################################################################
lightEntities = 'group.all_lights_only'
lights_on = []
for entity_id in hass.states.get(lightEntities).attributes['entity_id']:
state = hass.states.get(entity_id)
dt = state.last_changed + datetime.timedelta(hours=2)
time = '%02d:%02d' % (dt.hour, dt.minute)
if hass.states.get(entity_id).state is 'on': #and entity_id not in excluded
lights_on.append(hass.states.get(entity_id).attributes['friendly_name'])
if len(lights_on) > 0:
picture = '/local/lights/hue_pl.png'
message = ', '.join(lights_on)
sensor_message = 'Lights on: ' + message
lights_desc = '=- Lights on: {} -- {} since {}'.format(lights_on, message,time)
uom = 'Lights'
if len(lights_on) == 1:
uom = 'Light'
else:
picture = '/local/lights/bulboff.png'
message= ''
sensor_message= 'No lights on'
uom = 'Lights'
sensor_lights_desc = '{}'.format(sensor_message)
hass.states.set('sensor.lampjes_badge', len(lights_on), {
# 'custom_ui_state_card': 'state-card-value_only',
'text': sensor_message,
'unit_of_measurement': uom,
'friendly_name': time,
'entity_picture': picture
})
The length of the actual topic string is at most 65536 bytes. This is a limit imposed by the mqtt spec, you can’t change it. It is also worth noting that the topic is encoded with utf-8, so you may have less than 65536 characters available.
The payload of the message is limited to 268,435,456 byte
With such a short template, you can use it in notifications and it won’t be 9000 lines of code. So you can probably drop the template sensor. Also, it looks like your second template uses this. Which is the only reason you have it. So you could just delete this all together and use the following optimized template:
- platform: template
sensors:
light_check:
value_template: >
{% set lights_on = states.light | selectattr('state','eq','on') | map(attribute='name') | list %}
{% if lights_on | length == 0 %}
No lights on.
{% elif lights_on | length == 1 %}
The {{ lights_on[0] }} light is on.
{% elif lights_on | length == 2 %}
The {{ lights_on[0] }} and {{ lights_on[1] }} lights are on.
{% else %}
The {{ lights_on[:-1] | join(', ') }}, and {{ lights_on[-1] }} lights are on.
{% endif %}
With these short templates, you can place the logic directly into your notifications without crowding up your yaml (instead of using the template, therefore being limited to the 255 characters).
this is very nice indeed!
you’d need a skip-list to prevent automatically created light groups from showing up, (of which tradfri and hue make a few)(reason I use lightEntities = 'group.all_lights_only' in the python script and other automations), and some further lineup embellishment, but indeed way cool. thx!
copied to my templating cook-book
If you place this into a script, then call the script when you need to notify someone, you won’t need the value template:
script:
light_notification:
sequence:
# This is Home Assistant Script Syntax
- service_template: {{ notify_entity_id }}
data_template:
message: >
{% set lights_on = states.light | selectattr('state','eq','on') | map(attribute='name') | list %}
{% if lights_on | length == 0 %}
No lights on.
{% elif lights_on | length == 1 %}
The {{ lights_on[0] }} light is on.
{% elif lights_on | length == 2 %}
The {{ lights_on[0] }} and {{ lights_on[1] }} lights are on.
{% else %}
The {{ lights_on[:-1] | join(', ') }}, and {{ lights_on[-1] }} lights are on.
{% endif %}
{% set lights_on = states.light | selectattr('state','eq','on') | map(attribute='name') | list %}
{% if lights_on | length == 0 %}
No lights on.
{% elif lights_on | length == 1 %}
The {{ lights_on[0] }} light is on.
{% else %}
The {{ lights_on[:-1] | join(', ') }}, and {{ lights_on[-1] }} lights are on.
{% endif %}
btw, it needed this too:
- service_template: >
{{ notify_entity_id }}
or quotes of course, but I prefer the multiline notation