pyvlx
pyvlx copied to clipboard
Controlling ON/Off switches
Hi, First: Thank you for this wonderful library, it is really good with clear documented code and it works really great 👍 But as nothing is perfect, I've a problem trying to get a Somfy io-homecontrol switch to work with it. I take a look at the file without any success to understand why the switch do not work... It works with two Velux remotes without problem, with one (KLR-200) configured from a synchro from the KLF-200. Getting the state is_on()/is_off() gives nothing. Same with asyncio commands to set_on()/set_off() but Nodes[] list it correctly. Here is what is inside the object's parameters:
<FrameGetAllNodesInformationNotification
node_id=3
order=3
placement=0
name='On/Off Switch'
velocity=Velocity.SILENT
node_type='NodeTypeWithSubtype.ON_OFF_SWITCH'
product_group=0
product_type=0
node_variation=NodeVariation.NOT_SET
power_mode=0
build_number=0
serial_number='None'
state=5
current_position='0xC800'
target='0xC800'
current_position_fp1='0xF7FF'
current_position_fp2='0xF7FF'
current_position_fp3='0xF7FF'
current_position_fp4='0xF7FF'
remaining_time=0
time='2020-09-12 15:21:45'
alias_array=''
/>
What I see is that the product have no power_mode, build_number and serial_number set. Some of your functions are using the serial_number, but I have seen nothing related the switch. As I'm using Home-Assistant, my hope is to see power switches supported in it through the Velux module (which uses pyvlx). Do you think you can do something about it to make it work?
Thank you very much for your help.
I just try the JavaScript velux-klf200-api in Node.js which is a raw wrapper (not as elaborated as your lib) to the KLF-200 API and get the light on/off at will. Here is a part of the code I've written to manage the on/off switch :
{
return velux.sendCommand({ api: velux.API.GW_COMMAND_SEND_REQ,
commandOriginator: 8, // SAAC
priorityLevel: 3,
parameterActive: 0,
functionalParameterMP: {valueType:'RELATIVE', value:100},
indexArrayCount: 1,
indexArray: [3],
priorityLevelLock: false,
lockTime: 0
}
A value of 100 is for OFF and a value of 0 is for ON. The KLF-200 sends:
apiText: 'GW_NODE_STATE_POSITION_CHANGED_NTF',
nodeID: 3,
state: 5,
stateTag: 'Done',
So something need to be changed in your code to get it to work. I've not taken the time to look at everything (far from that) but I'll take a deeper look in the coming days to see if it can be patched easily.
I just take a look at the code and made some tests. in parameter.py, you define the class SwitchParameterOn/SwitchParameterOff but there is no method to allow bytes conversion, so by modifying to:
class SwitchParameterOn(SwitchParameter):
"""Switch Parameter in switched 'on' state."""
def __init__(self):
"""Initialize SwitchParameterOn class."""
super().__init__()
self.set_on()
# DATADRAINER CHANGE - BEGIN
def __bytes__(self):
return self.raw
# DATADRAINER CHANGE - END
class SwitchParameterOff(SwitchParameter):
"""Switch Parameter in switched 'off' state."""
def __init__(self):
"""Initialize SwitchParameterOff class."""
super().__init__()
self.set_off()
# DATADRAINER CHANGE - BEGIN
def __bytes__(self):
return self.raw
# DATADRAINER CHANGE - END
the on/off switch is working with all four function set_on()
, set_off()
, is_on()
and is_off()
, getting the following debug:
Putting "On/Off Switch" ON Here light switch on and state check gives: "On/Off Switch" is ON 10 s delay Putting "On/Off Switch" OFF Light switch off, and state check gives "On/Off Switch" is OFF
Edited: And in the same time it could useful to add a line from .on_off_switch import (OnOffSwitch)
to init.py
Hope you can make this small correction so that it can be included in Home-Assistant. Have a nice day.