Can Help me make an automation or front end switch to control my Heating turning on and off Please

hi can anyone offer some help with an automation or switch i am trying to make work please

so i have an entity switch.sonoff_1000#####
this is my heating control switch ( on/off)
i have a temperature guage on my hotwater tank
that gives me numeric readings entity sensor.hwater

so i am trying to create a manual switch that turns on the heating , notifys me its on , after checking the temperature is below 50 from my sensor.hwater
it will then keep the heating on until it reaches 50, then notify me " the water is now hot " and then it should turn the sonoff back to off

it will need to read the state of the switch.sonoff as well , so if its already on , dont turn it on

i ideally would like this as a switch in lovelace

Hi Simon,

Maybe the Template Switch is something you can use. That way you can use a script to turn your heater on and off.

Goodluck and if you need anymore help please post your config, I can always look at it :slight_smile:

Sorry i forgot to add, im using lovelace yaml. will this work in there, or does it have to run in configuration.yaml

thankyou for your reply Robin

Lovelace is just the VIEW on the frontend. Are you actually in YAML mode or are you using the frontend to manage the VIEW?

Either way, template switches need to be created in configuration yaml if you want them available in the frontend.

so i have made this so far, but i think its missing the conditions i needed,
can you tell me how to add them please

switch:

  • platform: template
    switches:
    hot water switch:
    value_template: “{{ is_state(‘switch.sonoff_######’, ‘on’) }}”
    turn_on:
    service: switch.turn_on
    data:
    entity_id: sensor.hwater < 50.00
    turn_off:
    service: switch.turn_off
    data:
    entity_id: sensor.hwater > 50.00

so i only want the switch to be able to manually turn on , if sensor.hwater is below 50
and for it to turn itself off , when it reaches 50 or above .

not sure how i add that condition :slight_smile:
thankyou in advance ( i did try adding some conditon lines and running that in the template tool , but cant get it to work )

Can you format your code properly please?
It appears you are confusing a switch configuration for a script or an automation. A switch is neither of those things.

ok , i didnt know that.
i did try making this as an autmation , but im just not very good at it yet.
but i liked the ability to switch it from within lovelace, is that possible with an autmation ?

can you understand what i am trying to achieve, or have i made that to vague as well

Thankyou

I have written you a quick example:

#switch template

switch:
  - platform:
    switches:
      hot_water_switch:
        value_template: "{{ is_state('switch.sonoff_######', 'on') }}"
        turn_on:
          service: script.turn_on
          data:
            entity_id: script.hwater_turn_on
        turn_off:
          service: script.turn_on
          data:
            entity_id: script.hwater_turn_off

# Scripts
hwater_turn_on:
    alias: Turn on hwater
    sequence:

      #Check if temp is below 50
      - condition: numeric_state
        entity_id: sensor.hwater
        below: '50.00'

      #Turn on the switch
      - service: switch.turn_on
        data:
          entity_id: switch.sonoff_######

      #Wait untill temp is above 50
      - wait_template: "{{ states('sensor.hwater') >= '50.00' }}"

      #Turn switch off
      - service: switch.turn_off
        data:
          entity_id: switch.sonoff_######

hwater_turn_off:
    alias: Turn off hwater
    sequence:

      #Stop turn_on script
      - service: script.turn_off
        entity_id: script.hwater_turn_on
      
      #Turn switch off
      - service: switch.turn_off
        data:
          entity_id: switch.sonoff_######

This is just a starting point, hope it helps!
What notification-integration are you using?

I will reiterate, that Lovelace is JUST THE VIEW. The frontend. The “control” of your entities/devices/automations/scripts

There are a number of ways this can be done, but you need to understand the differences. Yes, you can control AUTOMATIONS from the front end.

Wow, i am going to try that now thankyou.

i use pushbullet, or call the service notify.contactme with a message

Cheers Robin

Hi Robin, i got it working , but it does not turn the water heater off at 50.00 celcius,
i am not sure how i would test a script , without running it. the turn on script starts the heater , i can see that
but when temperature had reached over 52 it still hadnt run the script to turn the heater off, and stop the script running.

thankyou.

Did you try and put in it YourHAip:8123/developer-tools/template . There you can see what the output of your code is. What do you see when you put in:

"{{ states('sensor.hwater') >= '50.00' }}"

there doesn’t seem to be a reason to make it so complicated.

basically you need two automations - one to turn the heater switch on only if the temp is below 50. the other will turn the heater switch off at above 50 (plus a bit to allow for hysteresis).

then you want to add in a manual “switch” to start the process rolling. So use an input_boolean for that.

the only thing you haven’t clarified is what happens if the temp is above 50 and then you turn the input boolean on? I assume that when you turn on the boolean you want to wait until the temp is below 50 then turn the heater switch on. then when the temp goes above (say) 52 you thyen want the swiutch to turn off and not be able to turn back on until you tell it to turn back on by using the boolean? At least that’s how I would do it…I think)

So if that’s case:

input_boolean:
  heater_control_boolean:
    name: Master Heater Control

automation:
  - alias: turn on the heater below 50
    trigger:
      platform: numeric_state
      entity_id: sensor.your_temp_sensor
      below: 50
    condition:
      condition: state
      entity_id: input_boolean.heater_control_boolean
      state: 'on'
    action:
      service: switch.turn_on
      entity_id: switch.sonoff_1000#####

  - alias: turn off the heater above 52
    trigger:
      platform: numeric_state
      entity_id: sensor.your_temp_sensor
      above: 52
    condition:
      condition: state
      entity_id: switch.sonoff_1000#####
      state: 'on'
    action:
      - service: switch.turn_off
        entity_id: switch.sonoff_1000#####
      - service: input_boolean.turn_off
        entity_id: input_boolean.heater_control_boolean

then just put the input boolean on a card in the lovelace configuration so you cvan see it and be able to easily turn it off and on and see its state

Thankyou Finity.
i will give this a go, and let you know .
to answer your questions ,
yes a manual switch on my front end, that will turn on my heater , if temp is below 50
if temperature is above 50 , it will not turn on , maybe tell me water is already hot .

and yes when temperature is equal to 50, turn the heater off and message me " waters hot "

Thankyou for you time and coding , i really apreciate it .
will try it and let you know how that runs for me .

i think i may have messed up the syntax on copying it , am trying it again , as the quotes looked different
in my scripts.yaml

will let you know thanks again

ok it all works it was me :slight_smile: thanks Robin that works really well thankyou so much.

is there a way at the front end of showing when a script is running , and how would i trigger the script
from the front end, i wanted a button i pushed and the cript would run, and tell me its running ?

thanks in advance

Hi Simon,

I’m interested in your setup as I’m trying to achieve similar control on my HWT.
I got a Sonoff TH16 with 4 x temperature probes attached to my tank monitoring the water temperature and I’m noticing some interesting values. For example the water temperature at the top of the tank drops slower compare to bottom which cools quickly once the water is being used at tap/shower.
Curious where your gauges gets the temperature from.

Thanks
J

Good to hear that its working!

There are a few ways you can make it visable from the Lovelace UI. I think I would make and binary_sensor template to check if the script is running and show this in lovelace (binary_sensors change colors in the interface where scripts do not).

Wrote you a little example:

binary_sensor:
  - platform: template
    sensors:
      hwater_script:
        friendly_name: "Status hwater script"
        value_template: >-
          {{ is_state('script.hwater_turn_on', 'on') }}

You can make any item of a glance-card call your service so maybe you can give the binary_sensor an tap_action so it can also activate it. that code can look something like this:

columns: 1
entities:  
  - entity: binary_sensor.hwater_script
    name: null
    tap_action:
      action: call-service
      service: script.turn_on
      service_data:
        entity_id: script.hwater_turn_on
show_name: false
show_state: true
title: Hwater
type: glance

Keep in mind that this is just an example and there are a lot of ways to get this done. Hope it helps! :slight_smile:

Hi Yulasinio
My Temp probe is in the middle of my hot water tank,
as you said the top is hotter that the bottom, theres two reasons, hot water rises and the feed to your hot water tank is at the bottom so as you use the hot water , from the top of the tank cold water enters to fill the void at the bottom.
hope this helps

Thanks. That’s why I was asking where your temp probe is placed, because if it was at the bottom where the thermostat is fitted your boiler will be ON constantly :slight_smile: