RemotePy icon indicating copy to clipboard operation
RemotePy copied to clipboard

Streamlined way to make custom signals.

Open Vendelator opened this issue 3 years ago • 2 comments

While i've yet to figure out how to successfully send a signal to my AC-unit, i wanted to create a method of making signals based on user input or data from MQTT client or similar.

This is currently missing in your programs from what i can tell.

I'm publishing this here because i'm not sure where to post suggestions? Sorry if this bothers you.

Crude method...

  • I start off by using your GUI program and re-record until i get the correct signal length, which seems to be 210.

  • I then make a spreadsheet of all combinations that i want to use and need to see to assess the code (which i have almost no understanding of).

  • I write down each "high" value for each setting. This looks like this: temp

  • Finally i use this spreadsheet to make a simple program that creates a signal based on what functionality i call.

# The different lenghts of signals
command_lenght = {"0":(8880),"1":(4440),"2":(1665),"3":(555)}

first_tuple = (4, 6, 16, 18) # Present in all signals...
temp_dict = {"16":(32,), "17":(26, 32),"18":(28, 32)} # Different highs for different temps
swing_dict = {"on":(), "off":(20, 22, 24)} # Different highs swing on/off
second_tuple = (46, 48, 50) # Present in all signals...
mode_lst = {} # Mode seems to be dependent on temperature settings only?
fan_dict = {"auto":(78, 82), "high":(78,), "mid":(80,), "low":(78, 80)} # Different highs for different temperatures
standby_dict = {"on":(158,), "off":()} # Only high that is not present in any Off versions.

# This field will be replaced by values from NodeRed
temp = str(input("temp? int: "))
swing = str(input("Swing? on, off: "))
fan = str(input("fan speed? low, mid, high, auto: "))
standby = str(input("Unit on or off? on, off: "))

# Creates a tuple with all high's in the signal.
high_commands = first_tuple + tuple(temp_dict["16"]) + swing_dict[swing] + second_tuple + fan_dict[fan] + standby_dict[standby]

print (high_commands)

# Uses the tuple to create a full signal.
def signal_compiler():
    send_command = []
    for r in range (210): # Full range UNKNOWN
        if r == 0: # The first extra long signal
            send_command.append(command_lenght["0"])
        elif r == 1: # The second extra long signal
            send_command.append(command_lenght["1"])
        elif r+1 in high_commands: #+1 because range starts with 0.
            send_command.append(command_lenght["2"])
        else:
            send_command.append(command_lenght["3"])
    #print (send_command)
    return send_command # Returns a completed signal within a List

print(lsignal_compiler()) # Displays the full signal list
print(len(signal_compiler())) # Prints the number of signals in the list

Once i can actually send signals to my AC-unit i can clean up this code. But as of now, all signals i create using input() gives the expected output, which is nice.

EDIT

I have now been able to send some code to control my AC-unit, and my script works fine, almost... Out of the 211 values in each signal, it seems 202, 204, 206 and 208 are unique. Meaning i have to manually store several tuples to be able to properly call the right signals.

The code looks like this now and is callable from other programs. The problem is how to best store the combinations of unique values.

T = 562 # NEC standard, Signal lenght (one T)

first_tuple = (4, 6, 16, 18) # Present in all signals...
temp_dict = {"16":(32,), "17":(26, 32),"18":(28, 32),"19":(26, 28, 32),"20":(30, 32)} # Different highs for different temps
swing_dict = {"on":(), "off":(20, 22, 24)} # Different highs swing on/off
second_tuple = (46, 48, 50) # Present in all signals
mode_dict = {} # Mode seems to be dependent on temperature settings???
fan_dict = {"auto":(78, 82), "high":(78,), "mid":(80,), "low":(78, 80)} # Different highs for different temperatures
standby_dict = {"on":(158,), "off":()} # Only high that is not present in any Off versions.
swing_dict_end = {"on":(182, 196, 200), "off":(180, 184, 196, 198, 200)}
unique_tuple = () # 202, 204, 206, 208
third_tuple = (210,) # Assuming the last bits are random....

# Uses the tuple to create a full signal.
def signal_compiler(temp, swing, fan, standby):
    send_command = (16*T, 8*T) # Start snippet of code
    high_commands = first_tuple + tuple(temp_dict[str(temp)]) + swing_dict[swing] + \
                    second_tuple + fan_dict[fan] + standby_dict[standby] + swing_dict_end[swing] + third_tuple # Bulk of the code
    for r in range (209): # Full range 211, add tuples to create one complete tuple with 211 values.
        if r+1 in high_commands: #+1 because range starts with 0.
            send_command = send_command + (3*T,)#(command_lenght["2"],)
        else:
            send_command = send_command + (T,)#(command_lenght["3"],)
    return send_command # Returns a completed signal within a tuple

# Example that prints a working signal and counts all elements within that tuple.
if __name__ == "__main__":
    print(signal_compiler("16", "on", "auto", "on")) # (temp, swing, fan, standby)
    print(len(signal_compiler("16", "on", "auto", "on")))

Vendelator avatar Jul 15 '22 22:07 Vendelator

OK. Are you trying to analyze the signal pattern and generate a signal for each state? It's a very smart way.

I recorded all the combinations of frequently used conditions..... If you want to analyze the signal, there is also the best OSS.

In the future, I would like to add a function to analyze signals. Thanks for your hint.

meloncookie avatar Jul 20 '22 16:07 meloncookie

Yes, i have been doing this manually, because i was hoping all code was in a random pattern. But a short snippet at the end does not follow a logical pattern which is problematic. So now i'm trying to figure out what is the most resource efficient way to store commands.

Should i build tuples and inject the snippet code based on input values. This would be the same code as above, but with 10-20 tuples with another 4 items in it. Or should i instead just store all modes i want to use in 211 item long tuples and place them in a dictionary. It would count for 10-20 tuples as well.

Vendelator avatar Jul 21 '22 21:07 Vendelator