thisIO
(Michael)
October 1, 2020, 3:15pm
1
Hello,
i made switch like this
ac_display:
friendly_name: "AC Display"
turn_on:
- service: script.ac_display
turn_off:
- service: script.ac_display
icon_template: >-
{% if is_state('switch.ac_display', 'on') %}
mdi:television-classic
{% else %}
mdi:television-classic-off
{% endif %}
But i got other icon
then television-classic and television-classic-off.
Important that in case of template is the same switch switch.ac_display - is is the problem and how can it be solved?
Thanks a lot!
tjntomas
(Tomas Jansson)
October 1, 2020, 4:33pm
2
You donโt have a value_template
defined. Try:
ac_display:
friendly_name: "AC Display"
value_template: "{{ is_state('switch.ac_display', 'on') }}"
turn_on:
- service: script.ac_display
turn_off:
- service: script.ac_display
icon_template: >-
{%- if is_state('switch.ac_display', 'on') -%}
mdi:television-classic
{%- else -%}
mdi:television-classic-off
{%- endif -%}
thisIO
(Michael)
October 1, 2020, 7:13pm
3
tjntomas:
ac_display:
friendly_name: "AC Display"
value_template: "{{ is_state('switch.ac_display', 'on') }}"
turn_on:
- service: script.ac_display
turn_off:
- service: script.ac_display
icon_template: >-
{%- if is_state('switch.ac_display', 'on') -%}
mdi:television-classic
{%- else -%}
mdi:television-classic-off
{%- endif -%}
Icon is now ok, but the button if always off, goes not on (((
tteck
(๐ฉ๐ฉ๐๐๐ ๐จ๐ฉ๐๐ง)
October 1, 2020, 7:44pm
4
ac_display:
friendly_name: "AC Display"
value_template: "{{ is_state('switch.ac_display', 'on') }}"
turn_on:
service: switch.turn_on
data:
entity_id: switch.ac_display
turn_off:
service: switch.turn_off
data:
entity_id: switch.ac_display
icon_template: >-
{%- if is_state('switch.ac_display', 'on') -%}
mdi:television-classic
{%- else -%}
mdi:television-classic-off
{%- endif -%}
tom_l
October 1, 2020, 7:47pm
5
Pretty sure you canโt use a self referencing value_template.
Think of it like this:
The switch is off, so the value_template = โoffโ.
You turn the Lovelace representation of the switch on.
The switch integration looks at the value_template to check the state of the switch and sees โoffโ. (The entity in the template isnโt updated until the template is updated).
So the Lovelace switch representation is turned off.
You need an independent feedback sensor for your switch state.
You could use an input boolean for this.
I thought an optimistic mode had been added to the template switch but I donโt see it in the docs.
thisIO
(Michael)
October 1, 2020, 7:51pm
6
tteck:
ac_display:
friendly_name: "AC Display"
value_template: "{{ is_state('switch.ac_display', 'on') }}"
turn_on:
service: switch.turn_on
data:
entity_id: switch.ac_display
turn_off:
service: switch.turn_off
data:
entity_id: switch.ac_display
icon_template: >-
{%- if is_state('switch.ac_display', 'on') -%}
mdi:television-classic
{%- else -%}
mdi:television-classic-off
{%- endif -%}
This switch turns on/off script .
tteck
(๐ฉ๐ฉ๐๐๐ ๐จ๐ฉ๐๐ง)
October 1, 2020, 7:57pm
7
ac_display:
friendly_name: "AC Display"
value_template: "{{ is_state('switch.ac_display', 'on') }}"
turn_on:
service: script.turn_on
data:
entity_id: script.ac_display
turn_off:
service: script.turn_off
data:
entity_id: script.ac_display
icon_template: >-
{%- if is_state('switch.ac_display', 'on') -%}
mdi:television-classic
{%- else -%}
mdi:television-classic-off
{%- endif -%}
Maybe?
thisIO
(Michael)
October 1, 2020, 8:05pm
9
because if this i did not added โvalue_templateโ
tom_l
October 1, 2020, 8:12pm
10
If you add two services to the turn_on and turn_off commands or put the input_boolean on/off service in your scrips you can use an input_boolean in your value template.
thisIO
(Michael)
October 1, 2020, 8:13pm
11
You mean i have to create extra input_boolean for this switch?
tom_l
October 1, 2020, 8:18pm
12
Actually no. I just looked at your switch a bit closer. So your script runs permanently unless you turn it off?
Try this:
value_template: "{{ is_state('script.ac_display', 'on') }}"
thisIO
(Michael)
October 1, 2020, 8:20pm
13
tom_l:
Actually no. I just looked at your switch a bit closer. So your script runs permanently unless you turn it off?
Try this:
Copy to clipboard
value_template: "{{ is_state('script.ac_display', 'on') }}"
no, script send RF comman to broadlink. I have already made so, it turns on, and then automatically off
tom_l
October 1, 2020, 8:21pm
14
Then why do you have this?
turn_off:
service: script.turn_off
That turns off your script. It does not call another script to turn off your display.
thisIO
(Michael)
October 1, 2020, 8:23pm
15
It sends command off to script when the switch is off
tom_l
October 1, 2020, 8:25pm
16
No. It turns off your script. I.e. stops a script from running. It wonโt send anything to your display.
thisIO
(Michael)
October 1, 2020, 8:28pm
17
Ah i this case yes, but actually it does not matter, because it use only one command.
It is the display of AC, it toggles with one button on and off, because of this turn_on and turn_off leads to one script
tom_l
October 1, 2020, 8:32pm
18
Yeah I just looked at your first post. That is the correct way.
Do you have any way to get the state of the display?
Smart switch power consumption, pingable IP address, anything?
If not, you will, have to use an input_boolean. And this will get out of sync if you have any other way of controlling the display other than home assistant. An IR remote control for example.
thisIO
(Michael)
October 1, 2020, 8:35pm
19
no, because of IR controlled AC.
Of course its clear.
Could you please post a yaml, because i do not completly understand you what i have do with input_boolean
tom_l
October 1, 2020, 8:41pm
20
Create an input boolean called display_state. Use it like this in your switch:
ac_display:
friendly_name: "AC Display"
value_template: "{{ is_state('input_boolean.display_state', 'on') }}"
turn_on:
- service: script.ac_display
- service: input_boolean.turn_on
data:
entity_id: input_boolean.display_state
turn_off:
- service: script.ac_display
- service: input_boolean.turn_off
data:
entity_id: input_boolean.display_state
icon_template: >-
{%- if is_state('input_boolean.display_state', 'on') -%}
mdi:television-classic
{%- else -%}
mdi:television-classic-off
{%- endif -%}