HI Markus!
Before, we discussed that all groups need the same entity count, and otherwise the summary wouldn’t run.
Only this week i discovered that isn’t necessary anymore! Which is one of my biggest wishes of all. I am so happy to tell you we can have any group in the summary card now, and are not forced to create special arranged groups. Which makes it so much more user friendly and usable!! Ive rearranged immediately, with great result!
Cool.
nice! took out the word ‘since’ in the group_des line, because it would show twice than in the summary
if (group_desc.find(' since ') > 0): #if (group_desc != ''):
dt = dt_prevstate + datetime.timedelta(hours=+1)
group_desc = '{} {}'.format(group_desc, '%02d:%02d' % (dt.hour, dt.minute))
in my lights section, which works perfectly, showing lights time on and off, i use:
dt = hass.states.get('automation.sense_lights_change').attributes.get('last_triggered')
and
lights_desc = '{} since {}'.format(lights_message,time)
lights_message being either:
lights_message = '=- Lights on: ' +', '.join(lights_on)
or
lights_message= '!- No lights on'
Might we not try that for the badges too?
needs adapting for the various groups, and equally called automations of course something like
dt = hass.states.get(‘automation.sense_{{group_format}}_change’).attributes.get(‘last_triggered’)`
check:
full code if your interested, and copied that for my switches too:
##########################################################################################
## 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_lights_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_lights_message = 'Lights on: ' +', '.join(lights_on) # was: 'Text' + ', '.join(entities_on)
else:
lights_message= '!- No lights on'
sensor_lights_message= 'No lights on'
sensor_lights_desc = '{}'.format(sensor_lights_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_lights_message,
'unit_of_measurement': 'Lights',
'friendly_name': time,
'entity_picture': '/local/hue_pl.png'
})
##########################################################################################
## Switches:
##########################################################################################
switches_group = 'group.iungo_switch_switches_template'
switches_message = []
sensor_switches_message = []
sensor_switches_desc = []
switches_desc = []
switches_on = []
total_on = hass.states.get('input_boolean.anything_on').attributes.get('switches_on')
for entity_id in hass.states.get(switches_group).attributes['entity_id']:
dt = hass.states.get('automation.sense_switches_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:
switches_on.append(hass.states.get(entity_id).attributes["friendly_name"])
state = hass.states.get(entity_id)
if len(switches_on) > 0:
switches_message = '#- Switches on: ' +', '.join(switches_on)
sensor_switches_message = 'Switches on: ' +', '.join(switches_on)
else:
switches_message= '!- No switches on'
sensor_switches_message= 'No switches on'
sensor_switches_desc = '{}'.format(sensor_switches_message)
switches_desc = '{} since {}'.format(switches_message,time)
hass.states.set('sensor.switches_badge', total_on, {
# 'custom_ui_state_card': 'state-card-value_only',
'text': sensor_switches_message,
'unit_of_measurement': 'Switches',
'friendly_name': time,
'entity_picture': '/local/switch.png'
})