GithubHelp home page GithubHelp logo

ubhits / ad-autofanspeed Goto Github PK

View Code? Open in Web Editor NEW
18.0 1.0 6.0 40 KB

Automatically control a room fan's speed based on a temperature sensor. Please :star: if you like this app :)

Home Page: https://www.youtube.com/c/ubhits

License: Apache License 2.0

Python 100.00%
appdaemon-apps appdaemon apps app home-automation homeassistant home-assistant hass hacs assistant

ad-autofanspeed's People

Contributors

ubhits avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ad-autofanspeed's Issues

When temperature changes at the same moment of end time the fan never turns off

Hello,
I noticed that if the home temperature is changing when the end time occurs there seems to be a battle of the callbacks and usually the temperature change callback wins. The result is the fan never turns off. I suggest you save your callback to a variable so when end time comes you can call self.cancel_timer and cancel the callback before calling fan/turn_off.

I can do a pull request later if you want or if you can fix it that's great too.

Great app!

the final script

hello,

the four speed are for the température of the system and dont for the cool of the room ( now I have a server in my room where I sleep finaly I want sleep)

the two version of loop don't work for print also I have removed the two loop :

#-------------------------------------------------------------------------------
# Name:        Azaretdodo
# Purpose:
#
# Author:      Dorian ROSSE
#
# Created:     06/11/2021
# Copyright:   (c) Dorian ROSSE 2021
# Licence:     <your licence>
#-------------------------------------------------------------------------------

def initialize(self):
    # DEFAULTS
    self.debug        = True;
    0 > self.low > self.medium > self.halfway > self.high
    self.start        = datetime.strptime("21:00:00", '%H:%M:%S').time()
    self.end          = datetime.strptime("09:30:00", '%H:%M:%S').time()
def temperature_change(self, entity, attribute, old, new, kwargs):

    if self.is_time_okay(self.start, self.end):
      room_temperature = float(new)
      fan_speed = self.get_target_fan_speed(room_temperature)
      self.call_service("fan/set_speed", entity_id = self.fan, speed = fan_speed)
      fan_speed_percentage = self.get_target_fan_speed(room_temperature)
      self.call_service("fan/set_percentage", entity_id = self.fan, percentage = fan_speed_percentage)


def get_target_fan_speed(self, room_temperature):

    # if sun is above horizon, then add offset
    sun_above_horizon = self.get_state(self.sun) == "above_horizon"
    offset = self.offset if sun_above_horizon else 0
    fan_speed = "off"
    fan_speed_percentage = 0

    if room_temperature < self.low + offset:
      fan_speed = "off"
    elif room_temperature >= self.low + offset and room_temperature < self.medium + offset:
      fan_speed = "low"
    elif room_temperature >= self.medium + offset and room_temperature < self.high + offset:
      fan_speed = "medium"
    elif room_temperature >= self.halfway + offset and room_temperature < self.hafway + offset:
      fan_speed = "halfway"
    elif room_temperature >= self.high + offset:
      fan_speed = "high"
    if room_temperature >= self.low + offset: fan_speed_percentage = 25
    if room_temperature >= self.medium + offset: fan_speed_percentage = 50
    if room_temperature >= self.halfway + offset: fan_speed_percentage = 75
    if room_temperature >= self.high + offset: fan_speed_percentage = 100

    self.debug_log(f"AUTO FAN SPEED: {str(room_temperature)}/{fan_speed}")

    if sun_above_horizon: self.debug_log(f" (SUN OFFSET)")
    self.debug_log(f"AUTO FAN SPEED: {str(room_temperature)}/{fan_speed_percentage}%" + (" (SUN OFFSET)" if sun_above_horizon else ""))

    return fan_speed
    return fan_speed_percentage


def hvac_daily_shut_off(self, kwargs):
    self.call_service("fan/turn_off", entity_id = self.fan)
    self.debug_log("FAN AUTO OFF")
def is_time_okay(self, start, end):
    current_time = datetime.now().time()
    if (start < end):
      return start <= current_time and current_time <= end
    else:
      return start <= current_time or current_time <= end

def debug_log(self, message):
    if self.debug:
      self.log(message)

how do you find my script ?

Regards.

Azaretdodo.

Pause script

Per your email request for an issue to be opened. Add a way to pause the script when a user wants to manually control the fan speed with remote.

Four Speed Fans, 25%-50%-75%-100%

The treatlife fan switch connected to Home assistant through the TUYA integration has four speeds, 25%-50%-75%-100%.

Create and optional parameter between mid and high that can control the fan at 75%.

Something like this?
speeds:
low: 67
medium: 69
med-high: 73
high: 76

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.