i just mentioned it to make sure you dont do things for the wrong reasons
ok, my yaml skills arenāt that great so there are people on here that can give you a much better answer here. but here is a shot. syntactically itās not all right, but it gives someone a starting place I think.
- alias: heaterOn
trigger:
- platform: state
entity_id: input_boolean.heater_switch
state: 'on'
condition:
- conditions: and
condition: state
entity_id: switch.heater
state: off
for:
minutes: 15
add template condition here for temperature
action
- service: switch.turn_on
entity_id: switch.heater
- alias: heaterOff
trigger:
- platform: state
entity_id: input_boolean.heater_switch
state: 'on'
condition:
- condition: state
entity_id: switch.heater
state: on
for:
minutes: 15
action
- service: switch.turn_off
entity_id: switch.heater
Will try it.
But it will not go off immediately after going on?
It should wait 15 minutes, but like I said, the syntax isnāt correct, I was doing it from memory.
Edit: Undeleted. I originally deleted my post because I found issues with it that I couldnāt resolve on the fly The automations below will not work as desired. Iāve undeleted it for completeness of the thread.
@Danielhiversenās suggestion below may be the best solution for you. However if the max desired temp is reached, it may continue to run until the time limit is also reached if you use the min_cycle_duration. I also believe it doesnāt have a max_cycle_duration, which means it will continue to run beyond your 15 minute target if it hasnāt reached target_temp.
@turboc, The trigger you have here will only trigger when the input_boolean is toggled on and the same for your off automation. These would only run one 15 minute cycle then stop because they are waiting for the input_boolean.heater_switch to change state again.
@anon35356645, I worked through the goal and think I have a solution. These two automation checks for the input_boolean, switch.heater state both on and off for 15 minutes, and your temperature sensorās state above and below your settings.
Anytime, any of these change, it will trigger the automation and flow through the action service_template to decide if it should be on or off.
- The last trigger needs to be populated with your temperature sensorās entity id and the min and max temps.
- The first two
elif
statements need to havetarget_value
replaced with your numerical target high and low temperatures.
- alias: Heater on auto temp
trigger:
- platform: state
entity_id: input_boolean.heater_switch
to: 'on'
- platform: state
entity_id: switch.heater
state: 'on'
for:
minutes: '15'
- platform: state
entity_id: switch.heater
state: 'off'
for:
minutes: '15'
- platform: numeric_state
entity_id: your temperature entity_id sensor.temperature
above: 22 your maximum temperature
below: 19 your minimum temperature
condition:
- condition: state
entity_id: input_boolean.heater_switch
state: 'on'
action:
- service_template: >
{% if trigger.to_state.state | float > target_value %}
homeassistant.turn_off
{% elif trigger.to_state.state | float < target_value %}
homeassistant.turn_on
{% elif states.switch.heater.state == "on" %}
homeassistant.turn_off
{% elif states.switch.heater.state == "off" %}
homeassistant.turn_on
{% endif %}
entity_id: switch.heater
- alias: Heater off with boolean
trigger:
- platform: state
entity_id: input_boolean.heater_switch
to: 'off'
action:
service: homeassistant.turn_off
entity_id: switch.heater
Let me know if you have questions. Iām certain there is a better way to do this and is is untested but I think is should do what youāre trying to. It would be great to hear this works for you.
Thanks will try
why you cancelled it?
I would recommend using a Generic Thermostat https://home-assistant.io/components/climate.generic_thermostat/
And set the target temperature from automations.
Sorry, Thought I had found an issue yesterday that I couldnāt fix. I looked it over again and canāt see the issue I thought I saw. It may work.
Edit: Iāve notice the issue with my post above. If you float text it will return 0.0 and then when it is compared to your min or max temp it will always return true. If any of the non-numerical triggers starts the automation, the template will use the that trigger and compare against your target temps.
Like I said, I knew it had problems. I do all that type of automation in AD now so Iām very rusty with my YAML. Thanks for stepping in and providing better guidance.
Iām not very good at templates yet but I like a challenge. I have not tested this so it may have errors but I think it might fit all of your requirements. You will need to set your min and max temps on the input_slider. You will have to replace everywhere it says sensor.temperature
with your temp sensorās entity_id. It would be great to hear if this works for you or if youāve found another solution. Best of luck.
Edit: Updated code to one automation and removed bugs
input_slider:
- target_temp:
name: Target Temp
min: 10
max: 27
step: .5
input_boolean:
heater_switch:
name: Heater Switch
initial: off
icon: mdi:thermometer-lines
automation:
- alias: 'Heater on auto temp'
trigger:
- platform: state
entity_id: input_boolean.heater_switch
- platform: state
entity_id: switch.heater
to: 'on'
for:
minutes: 15
- platform: state
entity_id: switch.heater
to: 'off'
for:
minutes: 15
- platform: numeric_state
entity_id: sensor.temperature
above: '{{states.input_slider.target_temp.state | float + 1}}'
below: '{{states.input_slider.target_temp.state | float - 1}}'
action:
- service_template: >
{% if
(states.sensor.temperature.state|float) >= (states.input_slider.target_temp.state|float + 1) or (states.input_boolean.heater_switch.state == 'off') %}
homeassistant.turn_off
{% elif
((as_timestamp (now()) -as_timestamp (states.switch.heater.last_updated)|float) >= 900) and (states.sensor.temperature.state|float) <= (states.input_slider.target_temp.state|float + 1) and (states.input_boolean.heater_switch.state == 'on') %}
homeassistant.toggle
{% elif
((as_timestamp (now()) -as_timestamp (states.input_boolean.heater_switch.last_updated)|float) <= 1) and (states.input_boolean.heater_switch.state == 'on') and (states.sensor.temperature.state|float) <= (states.input_slider.target_temp.state|float + 1) %}
homeassistant.turn_on
{% else %}
homeassistant.turn_off
{% endif %}
entity_id: switch.heater
thanks a lot, will try it out