Help with combining two on/off automations into one

Have you considered setting up a generic thermostat? In your configuration.yaml add

#
#Create a generic Thermostat for ??
#Use Temperature sensor located ??
#
climate:
  - platform: generic_thermostat
    name: Heating
    heater: light.heating_switch_on_off
    target_sensor: sensor.temp_and_humid_sensor_01_temperature
    min_temp: 15
    max_temp: 25
    target_temp: 20
    away_temp: 17

You can then set the state to away and it will control the temperature. Lots easier.

See here for further documentation:

If I understand the generic thermostat correctly, in it’s simplest form I don’t need to even add an automation for it, it runs completely from the configuration.yaml settings, right?
So if I want to set certain times for it to run during the day/night I would create two different thermostats, one for day and one for night temperatures, and create an automation them to run them at certain times. Correct?

It would be better to use one thermostat and set with an automation. The away temp is used while your away. If user tracking set up you can use that with an automation to set the thermostat to away. I use my cell phone attaching to my wifi (ubiquity) to say whether we are home or away. With multiple people you just need to create a group and use the group sensor for home or away.

I use an automation to control my thermostats with varying temperatures during the week and weekend. @123 gave a lot of help on this.

- id: 'Main Floor Thermostat Control Heating'
  alias: Main Floor Thermostat Control Heat Control
  description: 'Set the main floor thermostat for Heat'
  trigger:
    - id: 'schedule'
      platform: time
      at:
        - input_datetime.sp1_wk
        - input_datetime.sp2_wk
        - input_datetime.sp3_wk
        - input_datetime.sp4_wk
        - input_datetime.sp5_wk
        - input_datetime.sp1_wknd
        - input_datetime.sp2_wknd
        - input_datetime.sp3_wknd
        - input_datetime.sp4_wknd
        - input_datetime.sp5_wknd
    - id: 'override'
      platform: state
      entity_id: input_boolean.thermostat_main
      to: 'on'
      for: '00:00:30'
    - id: 'disable'
      platform: state
      entity_id: input_boolean.thermostat_main
      to: 'off'
      for: '00:00:30'
  condition: []
  action:
    - choose:
        - conditions:
            - "{{ trigger.id != 'disable' }}"
            - "{{ is_state('input_boolean.thermostat_main', 'on') }}"
          sequence:
            - service: climate.set_temperature
              target:
                entity_id: climate.main_floor
              data:
                temperature: >-
                  {% if now().isoweekday() in [1,2,3,4,5] %}
                    {% set weekday = {state_attr('input_datetime.sp1_wk', 'hour'): states('input_number.t1_wk'),
                                      state_attr('input_datetime.sp2_wk', 'hour'): states('input_number.t2_wk'),
                                      state_attr('input_datetime.sp3_wk', 'hour'): states('input_number.t3_wk'),
                                      state_attr('input_datetime.sp4_wk', 'hour'): states('input_number.t4_wk'),
                                      state_attr('input_datetime.sp5_wk', 'hour'): states('input_number.t5_wk')} %}
                    {{ weekday[now().hour] }}
                  {% else %}
                    {% set weekend = {state_attr('input_datetime.sp1_wknd', 'hour'): states('input_number.t1_wknd'),
                                      state_attr('input_datetime.sp2_wknd', 'hour'): states('input_number.t2_wknd'),
                                      state_attr('input_datetime.sp3_wknd', 'hour'): states('input_number.t3_wknd'),
                                      state_attr('input_datetime.sp4_wknd', 'hour'): states('input_number.t4_wknd'),
                                      state_attr('input_datetime.sp5_wknd', 'hour'): states('input_number.t5_wknd')} %}
                    {{ weekend[now().hour] }}
                  {% endif %}
        - conditions:
            - "{{ trigger.id == 'disable' }}"
          sequence:
            - service: climate.turn_off
              target:
                entity_id: climate.main_floor
              data:
                hvac_mode: 'off'
      default: []
  mode: single

@AllHailJ have you considered the custom scheduler-component/card for the scheduling?

Handy to have the schedule in Lovelace.

Thank you, I’ve set up the thermostat and will look at your automation example next.

I have it in Lovelace but it is not pretty - especially with two thermostats. I will look at the custom scheduler-component/card. Many thanks!

That looks handy indeed, I’ll have a play with it!

Really handy. That makes it too easy. I spent days trying to figure out the automation. Man, was I dumb!!

@AllHailJ - we all started at ground zero with HA. Still finding new things that amaze me every week :slight_smile:

@gerrit.eu

The scheduler is way cool. Here is a screen shot to show how easy.

I seem to get more than I contribute but I’ll keep trying.

Best Regards to all

@AllHailJ you can have it in one schedule

But I could only get 2 set points inside a scheme and I wanted 4

I’ve got a bunch with five. Helps to use a PC as they can be difficult to select using a phone.

I also had 5 or more…without any issues. Example:

Just figured it out. Thanks

So I set up the thermostat, and added the scheduler, very nifty thank you! Only problem is that my heating is not coming on when the temperature drops below the set value (1 degree Celsius below target temp).
The climate card does display the correct temperature sensor values so there’s no problem reading the value. The heating comes on if I switch it on manually through HA, so that works. It just seems like the thermostat is not triggered. I know where to debug automations, but I can’t find where/how to debug the thermostat.
As a test, I removed my scheduler setting and tested the thermostat on its own, but no luck.
Can you spot anything wrong in my config?

climate:
  - platform: generic_thermostat
    name: Heating
    unique_id: climateday01
    heater: light.heating_switch_on_off
    target_sensor: sensor.temp_and_humid_sensor_01_temperature
    min_temp: 15
    max_temp: 25
    ac_mode: false
    target_temp: 17.5
    cold_tolerance: 1
    hot_tolerance: 0
    min_cycle_duration:
      seconds: 60
    initial_hvac_mode: "off"
    away_temp: 15
    precision: 0.1
heater string REQUIRED
entity_id for heater switch, must be a toggle device

Does your light switch fulfill this condition? Anything in HA logs?

I think I figured it out. If the initial_hvac_mode is set to “off”, it’s like a master switch that would keep the heating off until I switch it to “heat”. So it never gets a chance to regulate the heating itself unless I switch the thermostat on.
I changed initial_hvac_mode now to “heat” so that if I restart HA, the thermostat would start up enabled so it can control the heating.
Simple, but I needed to understand what the initial_hvac_mode value does first before figuring this out.
Testing it now.

It’s a Sonoff ZBMini switch, so it should be good for the purpose. See my previous post, looks like I figured it out.

I call service “scheduler.run_action” after restart of HA to make sure thermostat switches to correct state. Otherwise I think it would switch on next set point change.

1 Like