So I’m starting to work on my app for my whole house fan.
The fan has 2 speeds low and high. I can’t have one on if the other is already on otherwise it could burn up the motor or something else.
I also can’t allow the fan to run if my windows are closed.
Eventually I’m going to add to this to build in temperature control that will only allow the fan to run based on the outside temp and also adjust the speed of the fan based off of the difference of the current house temp minus where I want to get the house to. That will all come later. For now since I’m operating the fan manually through the dashboard I just want to ensure that if someone else were to manually engage the fan that the script does its checks and balances and makes sure that the following conditions are met and then we’re all good. Ideally it would be awesome to tell HA don’t send the command to the switch without doing the scirpt first but I don’t know if thats possible, or would we design a virtual switch that when its turned on causes this to run and then this will actually call the physical device?
Anyways just wanted a second set of eyes to take a look at this and make sure that I’m doing good code here
import appdaemon.plugins.hass.hassapi as hass
class fan_control(hass.Hass):
def initialize(self):
self.fan_low('switch.whole_house_fan_low')
self.fan_high('switch.whole_house_fan_high')
self.media_player = 'media_player.living_room'
self.listen_state(self.fan_low_cb, self.fan_low)
self.listen_state(self.fan_high_cb, self.fan_high)
# First we need to check and make sure that the other fan speed is not on. If it is turn it off
def fan_low_cb(self, entity, attribute, old, new, kwargs):
if self.get_state(self.fan_high) == "on":
self.turn_off(self.fan_high)
self.window_check
def fan_high_cb(self, entity, attribute, old, new, kwargs):
if self.get_state(self.fan_low) == "on":
self.turn_off(self.fan_low)
self.window_check
# We now need to check and make sure we have at least one open window so we can operator safely
def window_check(self,kwargs):
if self.get_state("sensor.matt_window") and self.get_state("sensor.family_room_window") and self.get_state("sensor.dining_room_window") == "closed":
if self.get_state(self.fan_low) == "on":
self.turn_off(self.fan_low)
else
self.turn_off(self.fan_high)
self.log("Announcing that all windows are closed")
self.call_service("media_player/volume_set", entity_id=self.media_player, volume_level = 50)
self.call_service("tts/google_say", entity_id=self.media_player, message = "All of the windows are closed. Due to safety reasons I cannot turn on the whole house fan until at least one window is open")