Climate and automation

In my vacation house, I try to automaticly put a heat pump in preset_mode “away” when the sun is down and to “none” preset_mode when sun is up and warming.
But I cannot get the automation to work correct.
It switches to “away” mode in afternoon but it does not go to “none” in the beginning of the day.
What am I doing wrong?

Home Assistant 0.102.0.dev20191110

climate:
  - platform: generic_thermostat
    name: Study
    heater: switch.compressor
    target_sensor: "sensor.room_temperature"
    min_temp: 8
    max_temp: 23
    ac_mode: False
    target_temp: 12
    cold_tolerance: 0.5
    hot_tolerance: 0
    min_cycle_duration:
      minutes: 30
    keep_alive:
      minutes: 5
    away_temp: 12
    
automation:
  - id: 'less_cold_hours'
    alias: none mode
    trigger:
    - event: sunrise
      offset: "03:00:00"
      platform: sun
    action:
    - data:
        entity_id: "climate.study"
        preset_mode: "none"
      service: climate.set_preset_mode

  - id: 'cold_hours'
    alias: Away mode
    trigger:
    - event: sunset
      offset: "-01:00:00"
      platform: sun
    action:
    - data:
        entity_id: "climate.study"
        preset_mode: "away"
      service: climate.set_preset_mode


States:
hvac_modes: heat,off
current_temperature: 15.5
min_temp: 8
max_temp: 23
temperature: 12
hvac_action: idle
preset_mode: away
preset_modes: none,away
friendly_name: Study
supported_features: 17

/Jorgen

Apparently you can’t set preset_mode to none via the climate.set_preset_mode service. I ran into the same problem when I was trying to set my Nest thermostat to eco mode and then back to what it was before. My solution is documented below. I think the same would work for you, except substitute away for when I use eco.

I used to be able to do so when I was using away_mode. As far as I remember they muddled it up and wanted “None” instead of ‘none’ despite showing it ‘none’ in UI.
Anyway, I think they’ve fixed it in generic_thermostat BUT I’d discourage people of using away preset as it’s buggy there (for example, it always gets the away_temperature from the config so if you change it in UI, it will be lost after going awaynone), I just ended up creating my own set of automations to store/activate night/normal presets.

Just in case you still need it, here’s my automations dealing with away preset:

## restore operating parameters
    # turn off away_mode to restore target temperature
    - service: climate.set_preset_mode
      data_template:
        entity_id: '{{ entity_id }}'
        preset_mode: 'none'
    # restore last target temperature
    - service: climate.set_temperature
      data_template:
        entity_id: '{{ entity_id }}'
        temperature: "{{ states('input_number.heating_target_temperature') }}"
        hvac_mode: "{{ states('input_text.heating_operation_mode') }}"
    # turn on away_mode to restore away_temperature (UGLY!)
    - service: climate.set_preset_mode
      data_template:
        entity_id: '{{ entity_id }}'
        preset_mode: 'away'
    # restore last away temperature
    - service: climate.set_temperature
      data_template:
        entity_id: '{{ entity_id }}'
        temperature: "{{ states('input_number.heating_away_temperature') }}"
        hvac_mode: "{{ states('input_text.heating_operation_mode') }}"
    # restore preset_mode
    - service: climate.set_preset_mode
      data_template:
        entity_id: '{{ entity_id }}'
        preset_mode: "{{ states('input_text.heating_preset') }}"
    # restore hvac_mode
    - service: climate.set_hvac_mode
      data_template:
        entity_id: '{{ entity_id }}'
        hvac_mode: "{{ states('input_text.heating_operation_mode') }}"