using this python
dt_prevstate = None
utc_offset = hass.states.get('sensor.utc_offset').state
timeDifference = float(utc_offset)
group = 'group.all_lights_only'
fname = 'Lights'
on_format = 'Lights on: {} -- {}'
off_format = 'No lights on since '
filter = 'on'
pic = 'lamp_off|lamp'
icon = 'mdi:lightbulb'
# min_show = 0
count = 0
desc = ''
for entity_id in hass.states.get(group).attributes['entity_id']:
state = hass.states.get(entity_id)
if (state.state == filter or debug):
dt = state.last_updated + datetime.timedelta(hours= timeDifference)
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)
count = count + 1
desc = '{} {} ({}), '.format(desc,state.name,time)
else:
if (dt_prevstate is None):
dt_prevstate = state.last_changed
else:
if (not state.last_changed is None):
if (state.last_changed > dt_prevstate):
dt_prevstate = state.last_changed
works fine. and shows me all light that are ‘on’, with their respective last_changed time.
However, Ive had to turn on allow_unreachable: true
for my Hue lights, which makes unreachable lights show as ‘on’ if they are ‘on’ in the Hub. That is a bit silly, because now all my outside night lights show ‘on’ in my setup, while in fact they are ‘unreachable’.
So I’d like to extend the above python with an if clause for a sub set of lights for which the reachable attribute is set in a binary_sensor and if that binary_sensor is ‘off’, it should be added to the list (desc in the python)
the binaries follow the naming of the lights of course:
binary_sensor.backdoor_outdoors_reachable light.backdoor_outdoors
binary_sensor.bureau_marte_reachable light.bureau_marte
binary_sensor.driveway_reachable light.driveway
binary_sensor.garden_backyard_reachable
binary_sensor.garden_terrace_reachable
binary_sensor.gate_outdoors_reachable
binary_sensor.mobile_reachable
binary_sensor.porch_outdoors_reachable
Please help me adding the logic to rule those out in the ‘on’ selection.
dont add to the list if
'binary_sensor.{}_reachable'.format(state.object_id) != 'on'
to give you an idea of what I am looking for.
thanks for having a look and time if you would