lalamite
(Chris)
August 18, 2019, 12:26pm
1
Hi guys,
I have added some picture entities including state_image
As I have some devices which are switched off using the original wall switch, the entity is not available after I restart home assistant (in case the lamp is switched off). Due to this, I always get this error message.
How can I ignore the availability of the entity (light.wohnzimmerlampe)?
Or better so say: If entity is not available, the state off picture shall be displayed.
This is the code:
- entity: light.stehlampe
show_name: false
show_state: false
state_image:
'off': /local/stehlampe-aus.jpg
'on': /local/stehlampe-an.jpg
unavailable: /local/stehlampe-aus.jpg
tap_action:
action: toggle
type: picture-entity
Error message:
jparthum
(Jason Parthum)
August 19, 2019, 8:20am
2
Instead of state_image
you could use conditional
cards. Since you’re only using two images you only need two conditions; state: "on"
and state_not "on"
:
type: conditional
conditions:
- entity: light.stehlampe
state: "on"
card:
- entity: light.stehlampe
show_name: false
show_state: false
image: /local/stehlampe-an.jpg
tap_action:
action: toggle
type: picture-entity
type: conditional
conditions:
- entity: light.stehlampe
state_not: "on"
card:
- entity: light.stehlampe
show_name: false
show_state: false
image: /local/stehlampe-aus.jpg
type: picture-entity
…But if you decide to use a third image for ‘unavailable’ then you’d need four conditions contained in three conditional
statements:
type: conditional
conditions:
- entity: light.stehlampe
state: "on"
card:
- entity: light.stehlampe
show_name: false
show_state: false
image: /local/stehlampe-an.jpg
tap_action:
action: toggle
type: picture-entity
type: conditional
conditions:
- entity: light.stehlampe
state: "off"
card:
- entity: light.stehlampe
show_name: false
show_state: false
image: /local/stehlampe-aus.jpg
tap_action:
action: toggle
type: picture-entity
type: conditional
conditions:
- entity: light.stehlampe
state_not: "on"
- entity: light.stehlampe
state_not: "off"
card:
- entity: light.stehlampe
show_name: false
show_state: false
image: /local/stehlampe-nicht_verfügbar.jpg
type: picture-entity
lalamite
(Chris)
August 19, 2019, 10:21am
3
Thank you Jason.
Tried this code first only to check whether it works:
type: conditional
conditions:
- entity: light.stehlampe
state: 'on'
card:
- entity: light.stehlampe
image: /local/stehlampe-an.jpg
tap_action:
action: toggle
type: picture-entity
If state of the lamp is on, I get the following result:
No card type configured.
[
{
"entity": "light.stehlampe",
"image": "/local/stehlampe-an.jpg",
"tap_action": {
"action": "toggle"
},
"type": "picture-entity"
}
]
but card type is configured? Or do I miss anything?
jparthum
(Jason Parthum)
August 19, 2019, 7:28pm
4
Oops, I forgot an array can’t follow card:
(that’s why it doesn’t say cards:
)…
- type: conditional
conditions:
- entity: light.stehlampe
state: "on"
card:
entity: light.stehlampe
show_name: false
show_state: false
image: /local/stehlampe-an.jpg
tap_action:
action: toggle
type: picture-entity
- type: conditional
conditions:
- entity: light.stehlampe
state_not: "on"
card:
entity: light.stehlampe
show_name: false
show_state: false
image: /local/stehlampe-aus.jpg
type: picture-entity
Edit: But the type
s do need to be an array.
lalamite
(Chris)
August 20, 2019, 6:34am
6
Thank you.
Unfortunately the error message (entity unavailable) from the beginning is still there.
it seems to be because of this:
card:
entity: light.stehlampe
Even if state_not: ‘on’ the system checks the following code and realizes, that this entity is not existing (as I haven’t switched on the lamp after restarting home assistant)
jparthum
(Jason Parthum)
August 20, 2019, 7:29am
7
Hmm, I really thought that would work.
You could try changing state_not: "on"
to state: "unavailable"
assuming that’s what the state actually shows (you can check under the States tab in Developer Tools). You’d then need a third conditional
statement to also cover state: "off"
If that doesn’t work, I know a template_sensor will.
jparthum
(Jason Parthum)
August 20, 2019, 7:50am
8
If the above doesn’t work this should…
sensor:
- platform: template
sensors:
light_stehlampe:
value_template: "{{ states('light.stehlampe') }}"
(^ requires restart)
lovelace:
- type: conditional
conditions:
- entity: sensor.light_stehlampe
state: "unknown"
card:
entity: sensor.light_stehlampe
show_name: false
show_state: false
image: /local/stehlampe-aus.jpg
type: picture-entity
- type: conditional
conditions:
- entity: sensor.light_stehlampe
state_not: "unknown"
card:
entity: sensor.light_stehlampe
show_name: false
show_state: false
state_image:
'off': /local/stehlampe-aus.jpg
'on': /local/stehlampe-an.jpg
tap_action:
action: toggle
type: picture-entity
jparthum
(Jason Parthum)
August 20, 2019, 10:11am
9
While working on something else it struck me that this may be the simplest solution for your issue.
Just create a Template Binary Sensor …
binary_sensor:
- platform: template
sensors:
light_stehlampe:
device_class: light
value_template: "{{ is_state('light.stehlampe', 'on') }}"
(^ requires restart)
…then keep your original Card configuration (sans the ‘unavailable’ state) and just change the entity to the new sensor name…
- entity: binary_sensor.light_stehlampe
show_name: false
show_state: false
state_image:
'off': /local/stehlampe-aus.jpg
'on': /local/stehlampe-an.jpg
tap_action:
action: toggle
type: picture-entity
This sensor configuration will only return on
or off
, so your (slightly modified) original picture-entity card should always work.
Edit: typo
lalamite
(Chris)
August 20, 2019, 11:59am
10
Awesome, this should definitely work!
Thanks mate!!!
Now I only need to create an script (toggle lamps) as the toggle action won’t work as changing the status of the template sensor, would not turn of or on the lights
1 Like
jparthum
(Jason Parthum)
August 20, 2019, 12:11pm
11
lalamite:
toggle action won’t work
Oh, good catch – I totally overlooked that.
This should work though:
- entity: binary_sensor.light_stehlampe
show_name: false
show_state: false
state_image:
'off': /local/stehlampe-aus.jpg
'on': /local/stehlampe-an.jpg
tap_action:
action: call-service
service: light.toggle
service_data:
entity_id: light.stehlampe
type: picture-entity
1 Like
lalamite
(Chris)
August 20, 2019, 4:01pm
12
You are the best! Thank you very very much!
Works like a charm
1 Like
jparthum
(Jason Parthum)
August 20, 2019, 7:17pm
13
No problem, glad to hear it finally works.