Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Taylorp913 opened this issue May 24, 2021 · 5 comments
Open

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

Taylorp913 opened this issue May 24, 2021 · 5 comments

Comments

@Taylorp913
Copy link

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

@Taylorp913
Copy link
Author

Would you like me to make a pull request for this?

@UbhiTS
Copy link
Owner

UbhiTS commented Nov 3, 2021

Hi, after a year of a break, I'm back. Are you still using this automation? should I fix it ?

@Taylorp913
Copy link
Author

Haha yeah I will be using it as soon as tuya fixes their home assistant integration to re-enable the fan control. Ultimately I love this automation and brag about it all the time.

@UbhiTS
Copy link
Owner

UbhiTS commented Nov 4, 2021

i'm on it ... i'll send you a private version since I do not have any way to test it, once you confirm, will update the repo ...

@Azaretdodo
Copy link

Azaretdodo commented Nov 7, 2021

Hello,

I had the insight but I wasn't found the word for 75 percentage !

The good word is halfway !

(you can try with your word you will fall on a mistake),

by my side I have found the loop in 3.10 on google but it print nothing...

and the indent show is false :

[(https://docs.python.org/fr/3/reference/compound_stmts.html#the-match-statement)]

a teacher of python was say it isn't advice to use python 3.10 now...

the code is over :

#-------------------------------------------------------------------------------
# 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;
    self.low          = 67
    self.medium       = 69
    self.halfway      = 73
    self.high         = 76
    self.medium       = 70
    self.halfway      = 71
    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.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)

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

have a nice end of weekend from the France the sun is shining and it is sixteen to thirteen here,

Regards.

Azaretdodo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants