UbhiTS / ad-autofanspeed

Automatically control a room fan's speed based on a temperature sensor. Please :star: if you like this app :)
https://www.youtube.com/c/ubhits
Apache License 2.0
18 stars 6 forks source link

I am in rewrite your python script I am in line 89 I go back to the code the next week-end #10

Closed Azaretdodo closed 2 years ago

Azaretdodo commented 3 years ago

Hello,

I am in rewrite your python script I am in line 89 I go back to the code the next week-end,

Regards.

Dorian ROSSE.

UbhiTS commented 2 years ago

Hi, what's the fix you are making ?

Azaretdodo commented 2 years ago

Hello,

I was rewrite for python 3.8 and 3.9 but i need to rewrite for 3.10 👍🏼 it is just for keep the scripts run without new variable

How far are you by your side ?

Have a nice evening from the France it is eighteen past four here and the Sky is fallen,

Regards.

Azaretdodo.


From: Tarunpreet Ubhi @.> Sent: Wednesday, November 3, 2021 5:57:43 PM To: UbhiTS/ad-autofanspeed @.> Cc: Azaretdodo @.>; Author @.> Subject: Re: [UbhiTS/ad-autofanspeed] I am in rewrite your python script I am in line 89 I go back to the code the next week-end (#10)

Hi, what's the fix you are making ?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/UbhiTS/ad-autofanspeed/issues/10#issuecomment-959730369, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AHJN3ILRHVB2Z653A5RYXIDUKFZZPANCNFSM437H4VTQ. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

Azaretdodo commented 2 years ago

Hello,

I was add this end of code but it prints all the print ( my setup have a lot of fan),

Thank you in advance to check in an system with less fan !

the code is here :

'''
#-------------------------------------------------------------------------------
# Name:        module1
# Purpose:
#
# Author:      doria
#
# Created:     06/11/2021
# Copyright:   (c) doria 2021
# Licence:     <your licence>
#-------------------------------------------------------------------------------

def initialize(self):
    # DEFAULTS
    self.debug        = True;
    self.low          = 67
    self.medium       = 69
    self.high         = 73
    self.medium       = 70
    self.high         = 72
    self.offset       = 0
    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.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.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)

if fan_speed_percentage := 25:
        print("the fan is slow and cool")

if fan_speed_percentage := 50:
        print("the fan is moderate")

if fan_speed_percentage := 100:
        print("the fan is hight and hot")'''

Have a nice evening from the france it is eighteen past height and the sky is fallen,

Regards.

Azaretdodo.

Azaretdodo commented 2 years ago

Hello,

I was add this end of code but it prints all the print ( my setup have a lot of fan),

thank you in advance to check by your side,

the code is here :

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

def initialize(self):
    # DEFAULTS
    self.debug        = True;
    self.low          = 67
    self.medium       = 69
    self.high         = 73
    self.medium       = 70
    self.high         = 72
    self.offset       = 0
    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.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.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)

def self():
    case == self.low or self.medium or self.high
    match ==  self.low.print("the fan is slow and cool")
    match == self.medium.print("the fan is moderate and temperate")
    match == self.high.print("the fan is hight and hot")

Have a nice morning from the france it is eleven past three and the sun is shining,

Regards.

Azaretdodo.