@mviezzer First of all, thanks for sharing your config!
I’ve been trying to do the same (only more simplistic) for a while now and I just can’t get the content to show up in the frontend. I’ve got no idea what I’m doing wrong, but I must be missing something.
Alright, so I have a more simplistic summary (more like your earlier version). Below is everything I added to the config to make this work (or at least tried to):
python_scripts/summary.py:
lights_count = 0
content = ""
for entity in hass.states.entity_ids('light'):
light = hass.states.get(entity)
if (light.state == 'on'):
lights_count = lights_count + 1
if lights_count == 1:
content = "1 light is on.\n"
elif lights_count > 1:
content = "{} lights are on.\n".format(lights_count)
else:
content = "All lights are off.\n"
hass.states.set('sensor.summary', '', {
'custom_ui_state_card': 'state-card-text',
'text': content
})
Configuration for the frontend (as you can see I’m also using Custom UI, which is working fine):
javascript_version: es5
extra_html_url:
- /local/custom_ui/state-card-custom-ui.html
- /local/custom_ui/state-card-text.html
extra_html_url_es5:
- /local/custom_ui/state-card-custom-ui-es5.html
- /local/custom_ui/state-card-text.html
www/custom_ui/state-card-text.html:
<dom-module id="state-card-text">
<template>
<style is="custom-style" include="iron-flex iron-flex-alignment"></style>
<style>
.state {
@apply(--paper-font-body1);
color: var(--primary-text-color);
margin-left: 8px;
text-align: left;
line-height: 20px;
}
</style>
<template is="dom-repeat" items="[[computeStateDisplay(stateObj)]]">
<div class="state">[[computeItem(item)]]</div>
</template>
</template>
</dom-module>
<script>
Polymer({
is: 'state-card-text',
properties: {
hass: { type: Object },
stateObj: { type: Object },
},
computeStateDisplay: function (stateObj) {
var text = stateObj.attributes.text;
if (text == null) { text = stateObj.state };
return text.split("\n")
},
computeItem: function (item) {
return item.trim();
},
});
</script>
In my default view I have the following configured:
default_view:
view: yes
icon: mdi:home-assistant
entities:
- sun.sun
- group.custom
custom:
name: Custom
entities:
- sensor.summary
And this is my automation to call the Python script:
- alias: Trigger on script event
initial_state: 'on'
trigger:
- platform: event
event_type: call_service
event_data:
domain: script
action:
- delay: '00:00:02'
- service: python_script.summary
- alias: Trigger on light event
initial_state: 'on'
trigger:
- platform: event
event_type: call_service
event_data:
domain: light
action:
- delay: '00:00:02'
- service: python_script.summary
- alias: Time interval updates
initial_state: 'on'
trigger:
- platform: time
minutes: '/1'
seconds: 00
action:
- service: python_script.summary
This is the result:
As you can see, it doesn’t show up in the custom state card, but when I click on the state card it opens up the following popup window and the content does show up in there:
Also, on the States page in the Developer Tools section the sensor.summary
is updated constantly. Either because of the interval updates or the script / light updates, the text
attribute is correctly updated.
What am I missing? I would love to get some help from you or someone else on this. Any help is appreciated.