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

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 opened this issue May 2, 2021 · 4 comments

Comments

@Azaretdodo
Copy link

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
Copy link
Owner

UbhiTS commented Nov 3, 2021

Hi, what's the fix you are making ?

@Azaretdodo
Copy link
Author

Azaretdodo commented Nov 3, 2021 via email

@Azaretdodo
Copy link
Author

Azaretdodo commented Nov 6, 2021

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
Copy link
Author

Azaretdodo commented Nov 7, 2021

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.

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

2 participants