| 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 |
| 85 | station = WeatherStation(name="weather_station", desc="My simple weather station example", address="1.2.3") |
| 86 | |
| 87 | # Linking weather station Datapoints to Group Address |
| 88 | ETS.link(device=station, dp="temperature", gad="1/1/1") |
| 89 | ETS.link(device=station, dp="humidity", gad="1/1/2") |
| 90 | ETS.link(device=station, dp="wind_speed", gad="1/1/3") |
| 91 | ETS.link(device=station, dp="wind_alarm", gad="1/1/4") |
| 92 | ETS.link(device=station, dp="wind_speed_limit", gad="1/1/5") |
| 93 | ETS.link(device=station, dp="wind_alarm_enable", gad="1/1/6") |
| 94 | }}} |
| 95 | |
| 96 | All 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 | |
| 98 | We 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 | |
| 100 | That'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 | |