Automation to set Hive TRV to specific temp when phone leaves house

As the title says, I am looking for help setting up an automation that allows me to set a Hive Smart radiator valve to say, 15 degrees when my son’s phone leaves the house.

I have managed to create an automation that turns the valve off but I do not want it to turn off, I want to set it to a specific temperature.

I also want it to set to say 20 degrees when his phone comes back into the house.

Thank you in advance

anybody?

Thanks

Can you believe I found my code by asking chatgpt or whatever it’s called and it works

For anyone else ever needing it, here it is

alias: CHOOSE A NAME
description: CHOOSE A DESCRIPTION
trigger:

  • platform: state
    entity_id: device_tracker.NAME OF PERSON’S PHONE
    to: home (OR AWAY)
    action:
  • service: climate.set_temperature
    data:
    entity_id: climate.NAME OF ENTITY IN YOUR HA
    temperature: 20 OR WHATEVER YOU WANT

Anything in capitals you need to change

Where’s the part where it chooses to set the temperature temperature to either 15 or 20 degrees depending on whether the tracker is home or away?

This example can do that.

alias: example
trigger:
  - platform: state
    entity_id: device_tracker.somebody
    to:
      - home
      - not_home
    from:
      - not_home
      - home
condition: []
action:
  - service: climate.set_temperature
    target:
      entity_id: climate.hive
    data:
      temperature: "{{ iif(trigger.to_state.state == 'away', 15, 20) }}"

The purpose of the to and from options is to constrain the State Trigger only to the state-changes we want; we don’t want it to be triggered if the device_tracker’s state should ever change to/from unavailable.


EDIT

According to the documentation for Device Tracker, the state value not_home is used to indicate when the device is not in the home zone.

Spoke too soon. It seems if I force run the automation it works but when he comes home it doesn’t work. HA currently says his phone is home but the TRV is set as if he is away. I wonder, does anyone know how often an automation like this checks for a change of state?

the code I used has to be created in 2 automations. One for when he is away and it sets to 10 degrees and one for when he is home and it sets to 20 degrees.

The thing is, it’s not refreshing anyway. HA knows he is home yet the TRV stayed in the ‘away’ state

A State Trigger triggers when the entity it’s monitoring changes state.

hmm in that case something is amiss.

This is the code for when I leave the house

alias: Test on my phone
description: ""
trigger:
  - platform: state
    entity_id: device_tracker.iphone
    from: home
condition: []
action:
  - service: climate.set_temperature
    data:
      temperature: 10
    target:
      entity_id: climate.bedroom_radiator

This is the code for when I enter the house

alias: Test 2 on my phone
description: ""
trigger:
  - platform: state
    entity_id: device_tracker.iphone
    to: home
condition: []
action:
  - service: climate.set_temperature
    data:
      entity_id: climate.bedroom_radiator
      temperature: 20

They refuse to work but when I manually run them, they do and if I manually change the state of my phone to away, or home, it works

Your test results suggest device_tracker.iphone is failing to automatically changes to its location.

Look at the device_trackers recorded history and see if there’s any evidence that it’s actually changing state.

I have been checking that every time and it is not updating.

I have been for about 15 mini walks today to test it out :rofl:

The good news is that you now know why the automation isn’t being triggered.

The bad news is that the device tracker doesn’t work.

Yup.

Not sure where to go from here

Which integration are you using to produce the device tracker that represents the phone? Is it the mobile app? Whatever it is that creates the tracker, start there.

I created my entire HA setup on my PC and then downloaded the companion app once everything was created so I would expect it was originally produced on the PC but I cannot see anything wrong with any of it other than HA is not communicating with any of the 4 phones to say they are either home or away. From memory, when I first set up HA via my HA yellow, my iphone automatically was there on the devices list.

On the iphone app, my location history shows a background fetch every 10 minutes or so from 8am this morning. I have not left the house yet but I will see if it updates when I do.