Summary card and badges for people, devices and status (with python script and custom card)

I added a check… yes, some entity do not have the state.last_changed setted yet.

I added a way to configure that, it will only show when has the word "since’ (Nobody in home since )

My guess is brow and grey are not so basic colors like red, green, blue… so the engine (?) do not understand the names. Either way I usually set in hex, because most time I do not use blue BLUE, it’s blue-ish.

Not working because the badges are set in python (even using state_card_mode: badges). The other badges are working in groups… need find a way to workaround.

I didn’t implement that yet, but the idea is use a special char (like ‘<’) for indicate reverse order in the begining of theme string.

Ill check all of your developments… Cool.

made a few myself. Added 2 badges, and changed the presentation in Summary a bit. View at a glance is so much more revealing now:

23

accompanied with this in a simple dashboard (will add the other inputs also), gives a super control-center :wink:

26

the time settings in the 0 setting need checking, seems not to take the setting of the individual badges, but an all over time setting. Might be the error I spotted, will see if your correction takes that away.

What is was wondering is why the Nobody home doesn’t simply show the time even in case the count = 0 ? Wouldn’t that be even simpler?
one strange thing: if you log out a family member, but leave someone else, you don’t see that time of last change, only the time the member that is left is shown. Which of course isn’t the last change time…

Anyways, keep on developing :+1:

Cheers,
Marius

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 :wink:

    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:

48

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'
     })

that would be great indeed. Considering the functionality of the summary, I’ve called the 2 themes off_line and on_line, the first ‘counting’ up from 0 to 7 , the latter counting down obviously. Thus reflecting the ‘health’ of the system in signifying colors.

HI,

Had some fun today tweaking the settings, and adding a few badges with dedicated groups to monitor. A complete system at a glance, with colors and symbols in sync with the functional values.

0815

btw @mviezzer, how can i split this over 2 lines in the python script? the \ doesn’t work alright, stopping the list there, while it should continue:

this works fine, but is too long:

on_theme ='red_badge|yellow_badge|grey_badge|blue_badge|orange_badge|brown_badge|black_badge|green_badge'

No place to put the …

have a fine weekend, thanks!
Marius

hi @mviezzer

i noticed you started using the state-card-mode: badges.
Any luck with that? Ive also given it a try and put all badges in a card, but no effect at all…

Hi, just for testing purposes, no luck yet…

I see, same here. Ive tried to badge these sensors through customize, but that didn’t work either…
Made my way with it, and show them either on the top of the page, or changed the attributes to be of better use in a regular card for some of them:

quite satisfying as it is, still, always interested in follow-up development :+1:

@Mariusthvdb Do you by any change have a repository with your configuration?

@Mariusthvdb or @mviezzer have you been able to add automations as the last command? As far as I can see only scripts are now being picked up as the last command.

I’ve been trying to pick up automations, so that I can use its alias as the last command, but call_service and the automation domain doesn’t work. I also tried to pick up automation logs from the logbook_entry event:

  trigger:
    - platform: event
      event_type: logbook_entry
      event_data:
        domain: automation

But this causes a recursion, since this is used in an automation. So, I stepped away from both of those.

The reason why I want to show automations as the last command is because I trigger a TTS script in most of them. That script is now being shown as the last command for almost the entire day. So, it (almost) always shows something like ‘Last activity: Squeezebox TTS’, but I’d rather show something like ‘Last activity: Turning on lights at sunset (TTS)’ (which is an automation).

I’m now trying to use the custom variable component to set a ‘last command’ variable in an automation and retrieving that value in the last_command.py file whenever my TTS script is triggered (which is always triggered by an automation).

I’m wondering whether there’s a better way of doing it.

HI @mviezzer !

been a while, and have been building on the summary quite some bit…

I would like to ask you for a little help. I have added a few groups that have more members than the max number of the theme list ( i have 9 themes already…). But many more lights and switches :wink: I would like the script to show theme 9 when lights on >9 no matter how many more.

therefor, i need this max number option in the following bit i think:

       # Check for theme X index/count
        if (theme.find('|') > 0):
            list = theme.split('|')
            if (len(list) in [1, groups_count[idx]]):
                theme = list[len(list)-1]
            else:
                theme = list[groups_count[idx]]

there should be an extra If, testing if the groups_count[idx] > [themes] and if that is the case, have it select the last theme in the list.
Not sure how to put that in correct python though, could you please help?

Cheers,
Marius

Can someone please let me know the setup procedure because I cannot get this thing working?

setup procedure of what exactly? what do you have ‘setup’ (python_script?), and what do you want it to monitor

this is what i ended up with, guided by @petro.
completely forgot to post here, sorry for that.

        themelist = groups_theme[idx].split('|')
        if len(themelist) > 1:
            try:
                theme = themelist[groups_count[idx]]
            except IndexError:
                theme = 'green_badge' # Error badge
        else:
            theme = 'black_badge' # this will be your default theme

no more issues of the theming growing out of the max number of set themes. cool!

1 Like

So what I did:

  1. created a folder python_scripts and added summary.py
  2. created a folder config/packages and added summary.yaml
  3. added state-card-value_only.html to www/custom_ui
  4. added state-card-value_only.html to frontend in configuration and python_scrip to configuration.yaml
  5. Obviously nothing happened

What should I do next just to get the thing going and THEN I can do the modifications based on my needs?

you should ‘run’ the script…

either automatically (have to set automations for that) or manually in the dev-tools.

first call reload (to have the system load the scripts you have)

then call the script itself:

then read the obvious errors in the log… (since you dont have the script adapted to your local settings, it wil fail rather extensively :wink:

check to see if this is a typo here. missing python_scripT:

@Mariusthvdb so far everything went as you explained and now I am at the error step. Here is what i got from the log:

2018-06-28 16:11:16 ERROR (Thread-6) [homeassistant.components.python_script.summary.py] Error executing script: 'NoneType' object is not subscriptable
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/python_script.py", line 166, in execute
    exec(compiled.code, restricted_globals, local)
  File "summary.py", line 44, in <module>
  File "/srv/homeassistant/lib/python3.5/site-packages/RestrictedPython/Eval.py", line 35, in default_guarded_getitem
    return ob[index]
TypeError: 'NoneType' object is not subscriptable

since i use a completely modified summary.py, you have to tell whats on line 44…

you will encounter this line quite often for as long as the script tries to do something with an entity, you havent set yet, or has not been calculated yet.

I used summary.py listed on this thread and still haven’t made any change since I am not sure what should be changed.

cool.
line 44 for entity_id in hass.states.get(group).attributes['entity_id']:

reads the groups you set in line 29 groups = ['group.family', 'group.devices_default', 'group.devices_alwayson']

did you specify those?

btw if you check for sensor.summary or badge in the dev-tools States <> , does anything show up?