Nest Automatic Humidity Control

I had a central humidifier installed on my furnace yesterday and wired it into my Nest. I was disappointed to discover that the “smart” Nest only allows for a static minimum target humidity setting, rather than automatically adjusting the target humidity based on outside temperature. It’s necessary to reduce the target humidity as temperature drops to prevent condensation from forming inside your home and potentially damaging things. I was further disappointed to see that Nest removed the ability to set the target humidity via their official API. Using the unofficial Nest API and HASS I was able to do what I wanted fairly easily, and am sharing it here for anyone else who wants to do the same. I wrote my script in PHP using this library - https://github.com/gboudreau/nest-api.

I’m using Dark Sky for my weather sensor. I created a trigger using the outside temperature sensor to call my PHP script.

configuration.yaml changes:

automation:
- alias: "Nest auto target humidity control"
  trigger:
    # Trigger if the outside temp changes OR thermostat HVAC on/off state changes OR thermostat mode changes
    - platform: state
      entity_id: sensor.dark_sky_temperature
    - platform: state
      entity_id: sensor.kitchen_thermostat_hvac_state
    - platform: state
      entity_id: sensor.kitchen_thermostat_hvac_mode
  action:
    service: shell_command.update_nest_target_humidity

shell_command:
  update_nest_target_humidity: '/usr/bin/php /home/homeassistant/custom/scripts/update_nest_target_humidity.php {{states.sensor.dark_sky_temperature.state}} {{states.sensor.dark_sky_humidity.state}}'

and here’s my PHP script:

Hopefully this is useful to someone else.

6 Likes

Thanks for sharing this with the community! I never get tired of seeing creative solutions people come up with using HA.

How were you able to integrate your code with Nest to allow it to automatically controller humidity settings?

The PHP script I posted above is what talks to the Nest and sets the target humidity. Home Assistant calls the PHP script whenever the outdoor temperature changes.

Hi @joe248! Super new to the whole automation world, have had many issues with fluctuating temps causing condensation in my house using the Nest. Wondering if you can help guide me through the process of how this works! Appreciate the help!

Once again sorry newbie with all this…

Andrew

Sure, I can try to help guide you through it. Do you have Home Assistant installed and running yet?

Also, I’m assuming your Nest is set up to control your central humidifier?

When you say “wired” to your nest, you literally had to send a wire to the nest directly and connect? If so, which labeled one?

EDIT: Never mind, I found which one it goes to.

Hi,

I know I am reviving an old thread here but stumbled across this and this seems to be the only way to automatically control the target humidity from nest based on outside temperature. I have been able to run your php script successfully to update the target humidity from my rpi3b+ running on Raspbian Stretch Lite since I’ve installed the php7 packages on my raspberry pi. However, I am unable to execute the php script from Home Assistant as defined in your configuration.yaml, as there seems to be no php integration within hassio.

I would be very interested in knowing how you did manage to call that php script from the shell command as it seems to be the missing piece for me to achieve full automation on the nest humidity.

Thanks!

Sorry, I don’t use hassio and don’t really know anything about it. Are you not able to install PHP on it? What about looking for a Nest unofficial API library in python and re-writing my script to use that?

Couldn’t find a way to install php on it no, and from what I’ve seen people suggest converting php scripts to python. I may have found a NEST python API as you suggested, that may be the way to go for me.

Out of curiosity, what were you running HASS on ? Were you running it on Hassbian ? Either way, thanks for sharing your script, I’m quite happy I may get to achieve automation out of this.

Cheers

No problem; glad someone else got some use out of it. I’m using a PI 3B running the latest Raspbian.

Signed up for an account to ask this question:

I’m trying to get this set up on a Raspberry Pi, but I’m not getting any response back from the Nest as far as I can tell. Does the nest.class.php still work? Do I need to use the same password / account I would use to log into the Nest website, or should I be using the client_id and secret from setting up a developer account? Is there some other authentication trick I’m missing here?

Thanks!

Yes, it’s still working for me. Use the email and password you use to log into your Nest account, not the client_id / secret. There’s nothing else required to authenticate. Did you try running the library’s example script here?

I did - right now I’m trying to run a basic script that does nothing but run getDeviceInfo() and print the results. I get a long string of PHP errors that imply that when it tried to create the new instance of the Nest class it basically failed to do so. (index out of range for index 0, etc.) The line numbers for the errors show that it is getting into that routine in the class, but I haven’t started line-by-line tracebacks yet, because I wanted to verify that Nest hadn’t slammed the door on this API first.

Figured at least the first problem out - the API does NOT work with family member accounts. I had set up a separate account to use with the Pi, but it was getting no data back from nest. When I logged in as the owner, I started getting data.

Sorry for bringing up an old thread. Any updates on getting this automation to work on Hass.io? I don’t know php or python, but I can learn. :frowning: Would be awesome if someone can share their automation? Thanks a bunch

Ive been trying to set this up in homeassistant and I keep getting the following error:

2019-11-07 16:45:29 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `php -d display_errors=on /config/phpscripts/nest-api/nest-script.php {{states("sensor.dark_sky_temperature")}} {{states("sensor.nest_humidity_control_humidity")}}`, return code: 255

NoneType: None

Both sensors validate in the template tester in homeassistant dev tools…

My configuration.yaml looks like so:

shell_command:
  update_nest_target_humidity: 'php -d display_errors=on /config/phpscripts/nest-api/nest-script.php {{states("sensor.dark_sky_temperature")}} {{states("sensor.nest_humidity_control_humidity")}}'

the example script from the nest-api library seems to connect properly and display everything as well and when I run my php script from the command line with manually entered values. I think maybe the shell_command isnt evaluating the templates properly?

At some point my shell command changed to this:

shell_command:
  update_nest_target_humidity: '/usr/bin/php /home/homeassistant/custom/scripts/update_nest_target_humidity.php {{states.sensor.dark_sky_temperature.state}} {{states.sensor.dark_sky_humidity.state}}'

Try using the full path to PHP. It’s also possible the double quotes are affecting it.

I had the same error. I realized I did not download the nest.class.php (linked in the first post above), once I downloaded that into the same directory as the script I was running I made it further, then ran into a curl error, sudo apt-get install php-curl solved that one. All is working well now.

Hi Guys,

Does this php script work still? I read that the Nest API has humidity as ‘read only’ at this point.
Really excited to set this up!
Thanks!