Stop me before I do something stupid

Tags: #<Tag:0x00007f73ad0a5168> #<Tag:0x00007f73ad0a4e70>

I am building a smart window fan, somewhat similar to this fellow’s: https://www.hackster.io/Granpino/smart-window-fan-4b077e.

I do not yet use HA, although I can see it in my future. I have written a crude python code to control the fan (turn on if it is cooler outside than in). It tracks both humidity and temperature inside and out, and calculates the dew point. There is a relay attached to turn on the fans. These are all connected to a raspberry pi zero w. Before I go in any deeper, I could see wanting to connect this with home assistant in the near future. For example, I would like to store the data connected, make a web page to look at plots, etc. I know nothing about databases. Before I make any decisions on how to do this, how do I save myself (and maybe others who want to adopt this as a plugin time in the future? Maybe I should just start integrating it now in HA? Maybe I should store data in sqlite?

Any and all comments and insights are welcome!

The whole thing could be automated from home assistant without the need for the python code.

And to add to what Tom already wrote, you don’t need an “expensive” raspberry.
A simple ESP8266 is fine.
You could even stretch it to a ESP01 but that will probably hinder you very soon when you want to add more stuff to the board.

I did think about using an ESP8266, but have much more experience with the RPi. The cost difference is, what $3? Would it have enough pins for two sensors and two relays (one for the fans and one for the covers)?

I figured that HA could control the whole thing, but don’t know about the learning curve. I already knew Python and linux, so it would be quick. I also figured it would be litte lost time to switch over. Could you give me a pointer about starting such a program?

Thanks.

If I look at bought locally prices then a well known 8266 is about a third of the cost of a raspberry zero.
If I search on eBay the price on the raspberry is still about the same but the 8266 is now about 1/40th of the price.

I have no clue how to add a raspberry to Home Assistant. But a 8266 is well documented and pretty much whatever you want to build, you can just copy paste what you need.
Yes really.

Regarding GPIOs I did a quick Google with minimum brain power used.
8266 has 17 according to the top result of Google.
Raspberry zero says it has 40 but looking quickly at the pinout revealed lots of ground pins. So… Not really 40…

And regarding the “program” to run a 8266 with the sensor.
These eight lines is all you need:

And for relays you need GPIO switch:

Done…

Hello, I would also recommend an Esp8266 or ESP32, these are completely sufficient in terms of performance and are very stable in the system. The main reason is ESPHome. It is very easy to set up and also very easy to integrate into HA …

That does indeed look simple. And it looks like a ton of people must be using the ESP8266 in HA, which bodes well for long-term stability. Thanks for the pointers.

Either you have access to cheap 8266s that I can’t find, or have only expensive RPis available where you are. My search found only $7 for the former, whereas I pay at most $10 for the RPI0W, but usually on sale at $5.

Also, the board I saw showed only 8 pins, only some of which were GPIO. But you are right, there are different boards with as many as 17. But this page, for example,claims that only about 5 are robust enough for general use. Even in the worst case, though, that should be sufficient.

Maybe I’m looking at the wrong pi, but this is the first one I found on eBay:

Anyways…

If you look at ESPHome cookbook there is lots of examples of what others have built, and you can search here also.
I don’t know about this 5 pins… sounds strange to me but I don’t know for sure. Didn’t read it all either.

The board with 8 pins is probably not a 8266 but a 01.

Wow, that is expensive. My source sometimes goes down to $5. But you do need to add a microSD card.

That is cheap. Pity ‘store pickup only’.

So, I decided to check out HA. Installed it on a RPi4B, and added some integrations. I also bought an ESP8266, to see how easy or hard that is to set up. Boy, VolkerKa is right: ESPHome makes it extremely easy to flash those chips and use them. I found a diagram for the pin set on the module that I am using, NodeMCU. I felt safe using only pins D0-D4, since the others have special states on startup. There were sufficient ground pins, and 3.3V pins to power both sensors and the relay. Sure enough, everything works and HA sees the temps and humidities. It also provides a switch that triggers the relay. Very cool.

But now I either have to program the 8266 chip, or HA. I might try both, just because I want to learn both. Relevant here is using HA. I tried to set up an automation, but what I want is a little too complicated for the wizard. The wizard lets me turn on the fans if one of the temperatures enters a range. I am sure there is a way to make it switch on the fan when the outside temperature is lower than the inside. So, I have two questions where I would appreciate pointers.

  1. Where is a good place for a beginner to learn how to do such a program. Some examples would be great. I have looked around, but not really found what I need ATM, and am beginning to feel overwhelmed by all of the information.

  2. I would also like to report dew points inside and outside. I have an equation that allows me to calculate it from the temperature and relative humidity. It worked fine in my python code on the RPi.

You can create automations in the ESP chip, or in GUI of HA, as yaml in automations.yaml or Node RED.
Node RED is easy for those who are not programmers.
I struggle a bit because I enjoy coding and is new to Node RED but it’s very capable.
Far easier and more capable than GUI and yaml.

You should give it a try, but look at a few videos of it with Home Assistant first to get you started.

Edit:
About the different options I listed above.
There is one that differs in the bunch.
Coding the automation in the ESP chip will make the code run locally and without any connection.
All the other options requires a working WiFi.
But you could battery power the devices and have your automation run in a blackout if you made the automation in the ESP chip.
If there is a need for that…

I like doing it on the chip itself—seems more stable, and probably faster. Here is the esphome fall I used to do that, in case anyone stumbles on here with a similar question. I commented out the dewpoint calculation, because I switched to the more accurate sensors that do not measure humidity. But it does work.

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

# Enable Web server.
web_server:
  port: 80

# Sync time with Home Assistant.
time:
  - platform: homeassistant
    id: homeassistant_time

# Dallas is for DS18B20 probe
dallas:
  - pin: D1

# Sensors with general information.
sensor:
  # Uptime sensor.
  - platform: uptime
    name: "Fan Controller Uptime"

  # WiFi Signal sensor.
  - platform: wifi_signal
    name: "Fan Controller WiFi Signal"
    update_interval: 30s

#sensor:
#  - platform: template
#    name: "Dewpoint"
#    lambda: !lambda |-
#      return 243.04*(log(id(RH1).state/100.) + ((17.625*id(T1).state)/(243.04+id(T1).state)))/(17.625-log(id(RH1).state/100.)-((17.625*id(T1).state)/(243.04+id(T1).state)));
#    unit_of_measurement: "°C"

# Dewpoint calculated using equation (21) of this paper: Alduchov, O. A., and R. E. Eskridge, 1996: Improved Magnus' form approximation of saturation vapor pressure. J. Appl. Meteor., 35, 601–609
#[https://doi.org/10.1175/1520-0450(1996)035%3C0601:IMFAOS%3E2.0.CO;2]

# Individual sensors
#sensor:
  - platform: dallas
    address: xxxxxxxxxx
    name: "Fan outside temp"
    unit_of_measurement: "°C"
    accuracy_decimals: 2
    id: To

  - platform: dallas
    address: yyyyyyyyyyyyyy
    name: "Fan inside temp"
    unit_of_measurement: "°C"
    accuracy_decimals: 2
    id: Ti

# Fan relay
switch:
  - platform: gpio
    pin: D0
    name: "Fan Switch"
    id: smartfan

binary_sensor:
  - platform: template
    name: "Cooler Outside"
    id: cooler_outside
    lambda: !lambda |-
      if (id(To).state < id(Ti).state) {
        return true;
      } else {
        return false;
      }
    on_press:
      then:
        - switch.turn_on: smartfan
    on_release:
      then:
        - switch.turn_off: smartfan