HI,
i have this little python code section the sets the feedback i get for my alarmclock in 2 ways: a text bit, and a sensor with a badge:
All seems fine, until I check the state.state of the sensor, and its showing On Off, in its variations. Apparently it shows both the weekdays and weekends on/off setting. How could I correct this in the python (see below) so that it shows only 1 state…
relevant creation line is
hass.states.set('sensor.alarms_badge','', {
where ive taken out the state.state now with this effect:
(only weekdays showing)
using:
hass.states.set(‘sensor.alarms_badge’,state.state, {
shows on Off:
WE off Wd Off
also, why the wD state is shown with a capital O and the wE state without is unclear to me, since i don’t set it manually. Or would that be because it currently is a weekday?
##########################################################################################
## Alarm clock
## 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
alarms_uom = []
alarms_picture = []
alarms_fn = []
for entity_id in alarms_prefix:
state = hass.states.get('input_boolean.{}_enabled'.format(entity_id))
if state:
if state.state is '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_fn = 'Relax'
alarms_desc = '%- Alarm clock is not set, relax'
alarms_uom = 'Off'
alarms_picture = '/local/badges/alarm_off.png'
else:
alarms_fn = alarms_desc[:-2]
alarms_desc = '/- Alarm clock set at ' + alarms_desc[:-2]
alarms_uom = 'On'
alarms_picture = '/local/badges/alarm.png'
hass.states.set('sensor.alarms_badge','', {
'entity_picture': alarms_picture,
'friendly_name': alarms_fn,
'unit_of_measurement': alarms_uom,
'hidden': hidden,
'order': order
})