Yes, Nobody is showing again, it was a syntax error.
here’s my complete summary.py, ive changed several things, and added the lights section, working perfectly at the moment!

accompanying dashboard to check all went well:

Only thing i would love to see changed is a color for the lights in Summary card (cant seem to adapt the text-only html file doing so)
I have automations for the groups, rather then call the summary every 15 seconds or so. Works magic.
the error message for last_cmd, or any other .py file is because one of the mentioned objects isn’t available (yet). Not always very clear which one that is…
##########################################################################################
## https://github.com/maattdiy/home-assistant-config
## Screenshot: https://github.com/maattdiy/home-assistant-config/blob/master/screenshots/summary.png
## Script call: https://github.com/maattdiy/home-assistant-config/blob/master/config/packages/ha_triggers.yaml#L39
## Resources:
## https://home-assistant.io/components/python_script/
## https://home-assistant.io/docs/configuration/state_object/
##########################################################################################
debug = False
show_badges = True
show_card = True
group_count = 0
group_desc = ''
summary = ''
idx = 0
if debug:
event = data.get('event')
logger.error("\n\nSUMMARY: " + str(event))
##########################################################################################
## Group count (people and devices)
## Groups config: https://github.com/maattdiy/home-assistant-config/blob/master/config/groups.yaml#L267
##########################################################################################
# Entities summary by group name
groups = ['group.family', 'group.hubs_binary_pinged', 'group.critical_devices_state'] # Groups need to have same member_count
groups_format = ['+{} at home: {}', '{} in use: {}', '!{} offline: {}'] # Message prefix
groups_filter = ['home', 'on|playing|home', 'off|idle|not_home'] # Filter to list
groups_badge = ['Home', 'In use', 'Status'] # Badge 'belt' (unit_of_measurement)
groups_badge_pic = ['', '', 'ok|bug|critical'] # Pictures: none, one, or a list of pictures (in this case the picture position will match the count)
groups_min_show = [0, 0, 0] # Mininum count to show
groups_desc = ['!Nobody home', '', '+System ok'] # Can set the default description, for use in case count = 0
groups_count = [0, 0, 0]
for group in groups:
group_count = 0
group_desc = ''
for entity_id in hass.states.get(group).attributes['entity_id']:
state = hass.states.get(entity_id)
filter = groups_filter[idx]
if (state.state in filter.split('|') or debug):
dt = state.last_changed
dt = dt + datetime.timedelta(hours=+1)
time = '%02d:%02d' % (dt.hour, dt.minute)
# If state changed in the past days show the date too
if dt.date() < datetime.datetime.now().date():
time = '{} {}'.format('%02d/%02d' % (dt.day, dt.month), time)
group_count = group_count + 1
group_desc = '{} {} ({}), '.format(group_desc, state.name, time)
# Final format for this group
if (group_count >= groups_min_show[idx]):
if (group_count == 0):
group_desc = groups_desc[idx]
else:
group_desc = groups_format[idx].format(group_count, group_desc[:-2])
groups_desc[idx] = group_desc
groups_count[idx] = group_count
idx = idx + 1
##########################################################################################
## Badges updates
##########################################################################################
idx = 0
order = 2
if show_badges:
for badge in groups_badge:
if (badge != ''):
entity_id = 'sensor.{}_badge'.format(badge.replace(' ', '').lower());
hidden = False if (groups_count[idx] >= groups_min_show[idx] or debug) else True
fname = groups_desc[idx] if debug else ' '
picture = groups_badge_pic[idx].replace(' ', '').lower()
# Check for picture X index/count
if (picture != ''):
list = picture.split('|')
if (len(list) in [1, groups_count[idx]]):
picture = list[len(list)-1]
else:
picture = list[groups_count[idx]]
if (picture != ''):
picture = '/local/badges/{}.png'.format(picture)
hass.states.set(entity_id, groups_count[idx], {
'friendly_name': fname,
'unit_of_measurement': badge,
'entity_picture': picture,
'hidden': hidden,
'order': order
})
order = order + 1
idx = idx + 1
##########################################################################################
## Alarm clock
## Package: https://github.com/maattdiy/home-assistant-config/blob/master/config/packages/alarmclock.yaml
##########################################################################################
alarms_prefix = ['alarmclock_wd', 'alarmclock_we']
alarms_wfilter = ['1|2|3|4|5', '6|7']
alarms_desc = ''
idx = 0
for entity_id in alarms_prefix:
state = hass.states.get('input_boolean.{}_enabled'.format(entity_id))
if (not state is None):
if (state.state == 'on'):
# Show the alarm for the next day
if (str(datetime.datetime.now().isoweekday()) in alarms_wfilter[idx].split('|')):
state = hass.states.get('sensor.{}_time_template'.format(entity_id))
alarms_desc = '{}{}, '.format(alarms_desc, state.state)
idx = idx + 1
if (alarms_desc == ''):
alarms_desc = '!Alarm clock is disabled'
else:
alarms_desc = 'Alarm clock set at ' + alarms_desc[:-2]
##########################################################################################
## Mode:
## General package: https://github.com/maattdiy/home-assistant-config/blob/master/config/packages/profiles.yaml
## Developer package: https://github.com/maattdiy/home-assistant-config/blob/master/config/packages/developer.yaml
## Badges images: https://github.com/maattdiy/home-assistant-config/tree/master/www/profiles
##########################################################################################
mode_desc = ''
state = hass.states.get('input_select.mode')
# Get info
#dt = datetime.datetime.now()
#time = "%02d:%02d" % (dt.hour, dt.minute)
if (not state is None):
hidden = False #if (state.state != 'Normal') else True
if (state.state != 'Unknown'):
dt = hass.states.get('automation.mode_selection').attributes.get('last_triggered')
if (not dt is None):
time = "%02d:%02d" % (dt.hour+1, dt.minute)
hass.states.set('sensor.mode_badge',state.state, {
'entity_picture': '/local/modes/{''}.png'.format(state.state.replace(' ','').lower()),
'friendly_name': time, #was: ''
'unit_of_measurement': 'Mode',
'hidden': hidden,
'order': order
})
if not hidden:
mode_desc = '{}*{} mode selected at: {}\n'.format(summary, state.state, time)
##########################################################################################
## Activity:
##
##########################################################################################
activity_desc = ''
## Get activity description
state = hass.states.get('input_select.activity')
state_value = hass.states.get('input_select.activity').state
#time = '?'
# Get info
#dt = state.attributes.get('last_triggered')
#time = '%02d:%02d' % (dt.hour, dt.minute)
if not state is None:
hidden = False #if (state.state != 'Normal') else True
if state.state != 'Unknown':
dt = hass.states.get('automation.activity_selection').attributes.get('last_triggered')
if not dt is None:
time = "%02d:%02d" % (dt.hour+1, dt.minute)
if not hidden:
activity_desc = '{}*{} activity selected at: {}\n'.format(summary, state.state, time)
hass.states.set('sensor.activity_badge', state_value, {
'friendly_name': time, #state_value,
'entity_picture': '/local/activities/{' '}.png'.format(state_value.replace(' ','').lower()),
'unit_of_measurement': 'Act'
})
##########################################################################################
## Lights:
##########################################################################################
lights_group = 'group.all_lights_only'
#show only lights, not light groups
excluded = ['light.custom_group_for_group','light.custom_group_for_lights_2']
lights_message = []
sensor_message = []
sensor_lights_desc = []
lights_desc = []
lights_on = []
total_on = hass.states.get('input_boolean.anything_on').attributes.get('lights_on')
for entity_id in hass.states.get(lights_group).attributes['entity_id']:
dt = hass.states.get('automation.sense_lights_change').attributes.get('last_triggered')
dt = dt + datetime.timedelta(hours=+1)
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"])
state = hass.states.get(entity_id)
if len(lights_on) > 0:
lights_message = '+Lights on: ' +', '.join(lights_on) # was: 'Text' + ', '.join(entities_on)
sensor_message = 'Lights on: ' +', '.join(lights_on) # was: 'Text' + ', '.join(entities_on)
else:
lights_message= '!No lights on'
sensor_message= 'No lights on'
sensor_lights_desc = '{}'.format(sensor_message)
lights_desc = '{} since {}'.format(lights_message,time)
hass.states.set('sensor.lights_badge', total_on, {
# 'custom_ui_state_card': 'state-card-value_only',
'text': sensor_message,
'unit_of_measurement': 'Lights',
'friendly_name': time,
'entity_picture': '/local/hue_pl.png'
})
##########################################################################################
## Summary update
## Custom card: https://github.com/maattdiy/home-assistant-config/blob/master/www/custom_ui/state-card-value_only.html
##########################################################################################
for group_desc in groups_desc:
if group_desc != '' and not group_desc.endswith(': '):
summary = '{}{}\n'.format(summary, group_desc)
# original
# summary = '{}\n{}\n{}'.format(summary, alarms_desc, mode_desc)
## Add to final summary
summary = '{}\n{}\n{}\n{}\n{}'.format(summary, alarms_desc, activity_desc, mode_desc, lights_desc)
if show_card:
hass.states.set('sensor.summary', '', {
'custom_ui_state_card': 'state-card-value_only',
'text': summary
})