I’m not explaining very well.
Let me give a simple problem . Hopefully you can see what I’m trying to say.
We have a dumb heater on a simple smart switch. Via Home assistant we can add a thermostat sensor.
By creating a simple automation we can get the heater to turn on and off when the temperature hits a set temperature. We now have a smart heater.
We can add the switch to Lovelace and we now have an interface. Brilliant.
Then comes the complications. If the user switches the heater off the automation may switch it back on again. So we need some rules in the automation or turn the automation off.
However we solve the problem we need some additional logic , almost certainly some virtual switches.
If we can tie all the logic to the virtual switch, it simplify the problem and reduces the number of additional components to solve the problem.
For instance if we turn off the automation for two hours when the switch turns off
To do this currently we need :-
switch.heater
input_boolean.heater_stop
sensor.temp
automation.heater
automation.heater_check
alias: Smart Heater
description: Turn on heater < 19 degrees > 19 turn off
trigger:
entity_id: sensor.temp
platform: state
condition:
- condition: state
entity_id: input_boolean.heater_stop
state: 'off'
action:
- service_template: >
{% if states('sensor.temp') > 18 %}
switch.turn_off
{% else %}
switch.turn_on
{% endif %}
data:
entity_id: switch.heater
- service_template: >
{% if states('sensor.temp') > '18' %}
switch.turn_on
data:
entity_id: input_boolean.heater_stop
alias: Smart Heater check
description: is heater check on
trigger:
entity_id: input_boolean.heater_stop
platform: state
from: 'off'
to: 'on'
delay: '02:00'
action:
- service: switch_turn_off
data:
entity_id: input_boolean.heater_stop
The above code is crude (if it works at all ) and the logic is difficult , but you get the idea.
I’m sure there are better way to code it. The point is there lots of components .
my idea is this, tie all the logic to the switch
switch:
- platform: template
switches:
heat:
value_template: "{{ is_state('switch.heater', 'on') }}"
trigger_template: >
{% if states('sensor.temp') > 18 %}
'off'
(% else %}
'on'
{% endif %}
trigger_check: 00:05
turn_on:
service: switch.turn_on
data:
entity_id: switch.heater
turn_off:
service: switch.turn_off
data:
entity_id: switch.heater
service: trigger_check
data:
entity_id switch.heat
check: 02:00
Basically we move the automation into the entity
You can use this switch in Lovelace, present it to Alexa and Google. If you don’t need it anymore,
when you delete it , all the logic gets deleted as well.
Not sure if the above completely breaks the Home assistant engine, or more likely my logic is faulty or there already way of doing this