HI,
im using this script to see if my family members are home:
familyEntities = 'group.family'
and
def NameMyEntities(hass, entity_list, entity_state):
global timeDifference
names = []
for entity_id in hass.states.get(entity_list).attributes['entity_id']:
state = hass.states.get(entity_id)
dt = state.last_changed + datetime.timedelta(hours= timeDifference)
time = '%02d:%02d' % (dt.hour, dt.minute)
if state.state == entity_state:
name = '{} ({})'.format(state.attributes['friendly_name'], time)
names.append(name)
return names
home = NameMyEntities(hass, familyEntities, 'home')
away = NameMyEntities(hass, familyEntities, 'not_home')
and the creation of the sensor:
hass.states.set('sensor.family_home', count_home, {
'custom_ui_state_card': 'state-card-custom-ui',
'friendly_name': 'Family Home?',
'home': ', '.join(home),
'away': ', '.join(away),
'icon': whichIcon,
'count_home': count_home,
'count_away': count_away,
'family_count': familyCount,
'icon_color': icon_color,
'show_last_changed': 'true'
})
which has worked perfectly for entities in the group.family with only states ‘home’ and ‘not_home’.
I am moving to use more complete/complex device_trackers in the group.family, such as @pnbruckner 's life360, which has more states than these 2 of course.
So I need to adapt the line
away = NameMyEntities(hass, familyEntities, 'not_home')
to something like
away = NameMyEntities(hass, familyEntities, not is 'home')
how can I do that? Obviously this doesn’t work. Please have a look?