hi,
apparently one can not customize a sensor created in a python_script the way we can using regular or custom_ui templating. Ive used this:
sensor.family_home:
templates:
icon_color: >
{% if state === '0' %} 'rgb(128, 128, 128)'
{% elif state === '1' %} 'rgb(248, 248, 255)'
{% elif state === '2' %} 'rgb(30, 144, 255)'
{% elif state ==='3' %} 'rgb(0, 128, 0)'
{% elif state === '4' %} 'rgb(255, 255, 0)'
{% elif state === '5' %} 'rgb(255, 165, 0)'
{% elif state === '6' %} 'rgb(255, 165, 0)'
{% else %} 'rgb(117, 21, 120)'
{% endif %}
# {% if is_state('sensor.family_home', '0') %} 'rgb(128, 128, 128)'
# {% elif is_state('sensor.family_home','1') %} 'rgb(248, 248, 255)'
# {% elif is_state('sensor.family_home','2') %} 'rgb(30, 144, 255)'
# {% elif is_state('sensor.family_home','3' )%} 'rgb(0, 128, 0)'
# {% elif is_state('sensor.family_home','4') %} 'rgb(255, 255, 0)'
# {% elif is_state('sensor.family_home','5') %} 'rgb(255, 165, 0)'
# {% elif is_state('sensor.family_home','6') %} 'rgb(255, 165, 0)'
# {% else %} 'rgb(117, 21, 120)'
# {% endif %}
on this basic sensor created in Python_script:
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,
'show_last_changed': 'true'
})
as you can see ive enabled the custom_ui for this sensor, but no succes.
ive other python_script sensors using a templates attribute with succes. I cant find a way though to use the above template in this setting:
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,
**'templates': icon_color,**
'show_last_changed': 'true'
})
any thoughts on how to do this appreciated please?
thx,
Marius