Changes between Version 8 and Version 9 of Proposal


Ignore:
Timestamp:
May 27, 2013, 2:48:54 PM (11 years ago)
Author:
Frédéric
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Proposal

    v8 v9  
    3737
    3838# Instanciation of the weather station device object
    39 station = WeatherStation(name="weather", address="1.2.3")
     39station = WeatherStation(name="weather_station", desc="My simple weather station example", address="1.2.3")
    4040
    4141# Linking weather station Datapoints to Group Address
     
    4646ETS.link(device=station, dp="wind_speed_limit", gad="1/1/5")
    4747ETS.link(device=station, dp="wind_alarm_enable", gad="1/1/6")
    48 
    4948}}}
    5049
    51 That's it! As you can see, concepts used here are not new... This device can be then used from any other real device of your installation, through GADs {{{1/1/1}}} to {{{1/1/6}}}. All you have to do, is to link the Communication Objects of your real devices to these GADs, using the '''ETS''' application. For example, the DP Nr 4 will send the {{{"Alarm"}}} value over the bus when the wind speed will reach the value stored in DP Nr 5, but only if the value of the DP Nr 6 as been set to {{{"Enable"}}}.
     50''Note: I skipped some part of the code, like the device registration and other stuff like that''
    5251
     52That's it! As you can see, concepts used here are not new... This device can be then used from any other real device of your installation, through GADs {{{1/1/1}}} to {{{1/1/6}}}. All you have to do, is to link the Communication Objects of your real devices to these GADs, using the '''ETS''' application. For example, the DP Nr 4 will send the {{{"Alarm"}}} value over the bus when the wind speed will reach the value stored in DP Nr 5, but only if the value of the DP Nr 6 as been set to {{{"Enable"}}}. By linking this alram object to the alarm entry of you sun blinds, you can save them from destruction!
    5353
     54Ok, but how the device knows the current wind speed? Well, it does not... yet! Let's see how it can be done:
    5455
     56{{{
     57#!python
     58from pknyx.api import Device, ETS
    5559
     60# Weather station class definition
     61class WeatherStation(Device):
    5662
     63    # Datapoints (= Communication objects) definition
     64    DP_01 = dict(name="temperature", dptId="9.001", flags="CRT", priority="low", initValue=0.)
     65    DP_02 = dict(name="humidity", dptId="9.007", flags="CRT", priority="low", initValue=0.)
     66    DP_03 = dict(name="wind_speed", dptId="9.005", flags="CRT", priority="low", initValue=0.)
     67    DP_04 = dict(name="wind_alarm", dptId="1.005", flags="CRT", priority="high", initValue=""No alarm")
     68    DP_05 = dict(name="wind_speed_limit", dptId="9.005", flags="CWTU", priority="low", initValue=15.)
     69    DP_06 = dict(name="wind_alarm_enable", dptId="1.003", flags="CWTU", priority="low", initValue="Disable")
     70
     71    @Device.schedule.every(minutes=5)
     72    def readWindSpeed(self):
     73
     74        # How we retreive the speed is out of the scope of this proposal
     75        # speed = xxx
     76
     77        # Now, write the new speed value to the Datapoint
     78        self.dp["wind_speed"].value = speed
     79
     80        # Check alarm speed
     81        if speed >= self.dp["wind_speed_limit"].value and self.dp["wind_alarm_enable"].value == "Enable":
     82            self.dp["wind_alarm"].value = "Alarm"
     83
     84# Instanciation of the weather station device object
     85station = WeatherStation(name="weather_station", desc="My simple weather station example", address="1.2.3")
     86
     87# Linking weather station Datapoints to Group Address
     88ETS.link(device=station, dp="temperature", gad="1/1/1")
     89ETS.link(device=station, dp="humidity", gad="1/1/2")
     90ETS.link(device=station, dp="wind_speed", gad="1/1/3")
     91ETS.link(device=station, dp="wind_alarm", gad="1/1/4")
     92ETS.link(device=station, dp="wind_speed_limit", gad="1/1/5")
     93ETS.link(device=station, dp="wind_alarm_enable", gad="1/1/6")
     94}}}
     95
     96All we do, here, is adding a method periodically called by the framework (every 5 minutes in the above example). In this method, we retreive the wind speed (not explained here), and give the value to the Datapoint Nr 3. If the value has changed from the previous call, the Datapoint will automagically transmit it to the bus (according to the flags, of course).
     97
     98We also check if the speed has reached the speed limit; if so, we change the corresponding Datapoint value, which wil, in turn, send the value on the bus if needed (a special value of the flag, like in '''linknx''', can force the value to be sent, even if it does not change).
     99
     100That's it for now. This is only a draft version; final implementation may change, according to feedback/suggestions I will get. But the core is all there. Again, the goal of the framework is to provide very high level tools to build a complete and powerfull KNX extension.
     101
     102== Other ideas ==
     103