Commands

Commands are entities capable of forge messages for the KNX bus interpreting changes in Appliance state.

Commands compare an old Appliance state with a new one and create messages to be sent to the Appliance’s device.

Commands are designed to read Appliance’s attributes: home.appliance.attribute.mixin()

class knx_plugin.message.Command(data: dict)

A generic KNX command.

Example:
>>> import knx_stack
>>> import knx_plugin
>>> address_table = knx_stack.AddressTable(knx_stack.Address(4097), [], 255)
>>> association_table = knx_stack.AssociationTable(address_table, [])
>>> groupobject_table = knx_stack.GroupObjectTable()
>>> data = {"name": "DPT_SceneControl",
...         "addresses": [2823],
...         "fields": {"number": 7, "command": "activate"}}
>>> class C(knx_plugin.Command):
...     def make_msgs_from(self, old_state, new_state):
...         pass
>>> command = C(data)
>>> command.associate(association_table, groupobject_table)
>>> msgs = command.execute()
>>> msgs[0].dpt.number
7
>>> msgs[0].dpt.command
<Command.activate: 0>
execute() List[knx_stack.definition.layer.application.a_group_value_write.req.Msg]

Build one or more messages for the protocol Gateway, using the internal protocol message representation

Returns

a list of protocol messages

DPT_Brightness

class knx_plugin.command.dpt_brightness.Brightness(data: dict)
>>> import home
>>> import knx_plugin
>>> command = knx_plugin.command.dpt_brightness.Brightness.make([])
>>> command._asaps = [1]
>>> old_state = home.appliance.light.indoor.dimmerable.state.off.State()
>>> new_state = old_state.next(home.appliance.light.event.brightness.Event(10))
>>> new_state = new_state.next(home.appliance.light.event.circadian_rhythm.brightness.Event(20))
>>> new_state = new_state.next(home.appliance.light.event.lux_balancing.brightness.Event(30))
>>> new_state = new_state.next(home.appliance.light.indoor.dimmerable.event.forced.Event.CircadianRhythm)
>>> msgs = command.make_msgs_from(old_state, new_state)
>>> msgs[0].dpt.value
20
>>> old_state = new_state.next(home.appliance.light.indoor.dimmerable.event.forced.Event.Not)
>>> new_state = old_state.next(home.appliance.light.indoor.dimmerable.event.forced.Event.LuxBalance)
>>> msgs = command.make_msgs_from(old_state, new_state)
>>> msgs[0].dpt.value
30
>>> old_state = new_state.next(home.appliance.light.indoor.dimmerable.event.forced.Event.Not)
>>> new_state = old_state.next(home.appliance.light.indoor.dimmerable.event.forced.Event.On)
>>> msgs = command.make_msgs_from(old_state, new_state)
>>> msgs[0].dpt.value
10
DPT = {'addresses': [], 'fields': {'value': 100}, 'name': 'DPT_Brightness', 'type': 'knx'}
make_msgs_from(old_state: Union[Type[home.appliance.light.indoor.dimmerable.state.State], Type[home.appliance.light.indoor.hue.state.State]], new_state: Union[Type[home.appliance.light.indoor.dimmerable.state.State], Type[home.appliance.light.indoor.hue.state.State]])

Update the internal protocol message representation and call execute to build one or more messages for the protocol Gateway

Parameters
  • old_state – the old Appliance State

  • new_state – the new Appliance State

Returns

a list of protocol messages

Custom Clima

class knx_plugin.command.custom_clima.Setup(description)
>>> import home
>>> import knx_plugin
>>> import knx_stack
>>> cmd = knx_plugin.command.custom_clima.Setup.make([3202])
>>> cmd._asaps = [1]
>>> state = home.appliance.thermostat.presence.state.off.State()
>>> first_state = home.appliance.thermostat.presence.state.off.State([0.0, home.event.clima.season.Event.Winter,
...                                                  home.event.clima.command.Event.Off,
...                                                  home.appliance.thermostat.presence.event.setpoint.Event(19),
...                                                  home.appliance.thermostat.presence.event.keep.setpoint.Event(19)])
>>> msg = cmd.make_msgs_from(state, first_state)
>>> knx_stack.Long(value=msg[0].dpt.value)
0x10058C00
>>> "off" in str(msg[0].dpt)
True
>>> "140" in str(msg[0].dpt)
True
>>> second_state = home.appliance.thermostat.presence.state.keep.State([0.0, home.event.clima.season.Event.Winter,
...                                                  home.event.clima.command.Event.Keep,
...                                                  home.appliance.thermostat.presence.event.setpoint.Event(20),
...                                                  home.appliance.thermostat.presence.event.keep.setpoint.Event(19)])
>>> msg = cmd.make_msgs_from(first_state, second_state)
>>> knx_stack.Long(value=msg[0].dpt.value)
0x14058C00
>>> "riduzione_notturna" in str(msg[0].dpt)
True
>>> "140" in str(msg[0].dpt)
True
>>> third_state = home.appliance.thermostat.presence.state.on.State([0.0, home.event.clima.season.Event.Winter,
...                                                  home.event.presence.Event.On,
...                                                  home.event.clima.command.Event.On,
...                                                  home.appliance.thermostat.presence.event.setpoint.Event(20),
...                                                  home.appliance.thermostat.presence.event.keep.setpoint.Event(19)])
>>> msg = cmd.make_msgs_from(second_state, third_state)
>>> knx_stack.Long(value=msg[0].dpt.value)
0x18059600
>>> "automatico" in str(msg[0].dpt)
True
>>> "150" in str(msg[0].dpt)
True
DPT = {'addresses': [], 'fields': {'centralizzato': True, 'differenziale': 5, 'funzionamento': 'automatico', 'setpoint': 155, 'stagione': 'inverno', 'temporizzazione': 0, 'terziario': False, 'unita_misura': 'celsius', 'variazione_setpoint': 0}, 'name': 'DPTSetupClima'}
make_msgs_from(old_state, new_state)

Update the internal protocol message representation and call execute to build one or more messages for the protocol Gateway

Parameters
  • old_state – the old Appliance State

  • new_state – the new Appliance State

Returns

a list of protocol messages