Hallo,
was haltet Ihr von folgendem:
- ein Schalter item als Zeitschaltuhr läßt sich über die VISU einstellen
- in der VISU stelle ich die Felder für zwei crontabs für den Ein- und Ausschaltzeitpunkt ein
- über eine Logic modifiziere ich dann die crontab des item
Könnte etwa so aussehen:
im Item ein Unter-Item für die Zeitschaltuhr hinzufügen. Dieses verwaltet den CronTab String:
und die Logic, die die crontab ändert:
file logics/zeitschaltuhr.py
Damit das funktioniert, muss der scheculer.py wie unten gepatched werden.
das Widget geht sicher eleganter (Hilfe erwünscht!):
Widget JavaScript: UPDATE 08.12. 15:30h: init und update functions
was haltet Ihr von folgendem:
- ein Schalter item als Zeitschaltuhr läßt sich über die VISU einstellen
- in der VISU stelle ich die Felder für zwei crontabs für den Ein- und Ausschaltzeitpunkt ein
- über eine Logic modifiziere ich dann die crontab des item
Könnte etwa so aussehen:
im Item ein Unter-Item für die Zeitschaltuhr hinzufügen. Dieses verwaltet den CronTab String:
Code:
[aussen] [[vorn]] [[[licht2]]] name = Außenbeleuchtung type = bool visu_acl = rw sv_widget = "{{ basic.switch('item', 'item') }}<br>{{ basic.value('item_cron', 'item.zeitschaltuhr') }}" knx_dpt = 1 knx_send = 0/0/21 knx_init = 0/1/21 enforce_update = yes crontab = 0 17 * * = 1 | 0 7 * * = 0 [[[[zeitschaltuhr]]]] name = Zeitschaltuhr type = foo visu_acl = rw sv_widget = "{{ basic.crontab('item', 'item') }} " enforce_update = yes
Code:
[zeitschaltuhr] filename = zeitschaltuhr.py visu_acl = yes
Code:
#!/usr/bin/env python # logger.info("Zeitschaltuhr Value :" + trigger['value'] ) item_id = trigger['value'] item = sh.return_item(item_id) if item is not None : new_crontab = item() new_crontab = new_crontab.replace("_", " ").strip() logger.info("Zeitschaltuhr EIN/AUS :" + new_crontab ) item = item.return_parent() sh.scheduler.change(item.id(), cron=new_crontab) else: logger.info("Zeitschaltuhr ungueltig!")
das Widget geht sicher eleganter (Hilfe erwünscht!):
Code:
/** * Displays a crontab Zeitschaltuhr * * @param unique id for this widget * @param a gad/item * @param text printed on the checkbox */ {% macro crontab(id, gad) %} <div id="{{ uid(page, id) }}" data-widget="basic.crontab" data-item="{{ gad }}" value="{{ gad }}"> <label for="{{ uid(page, id) }}_wday_1" class="select">Einschalten jeden:</label> <fieldset data-role="controlgroup" data-type="horizontal" data-mini="true"> <select id="{{ uid(page, id) }}_wday_1" data-native-menu="false" multiple> <option data-placeholder="true">Tag</option> <option value="0">Montag</option> <option value="1">Dienstag</option> <option value="2">Mittwoch</option> <option value="3">Donnerstag</option> <option value="4">Freitag</option> <option value="5">Samstag</option> <option value="6">Sonntag</option> </select> <select id="{{ uid(page, id) }}_hour_1" data-native-menu="false" multiple> <option data-placeholder="true">Stunde</option> <option value="0" >00 Uhr</option><option value="1" >01 Uhr</option><option value="2" >02 Uhr</option><option value="3" >03 Uhr</option><option value="4" >04 Uhr</option> <option value="5" >05 Uhr</option><option value="6" >06 Uhr</option><option value="7" >07 Uhr</option><option value="8" >08 Uhr</option><option value="9" >09 Uhr</option> <option value="10">10 Uhr</option><option value="11">11 Uhr</option><option value="12" >12 Uhr</option><option value="13" >13 Uhr</option><option value="14" >14 Uhr</option> <option value="15">15 Uhr</option><option value="16">16 Uhr</option><option value="17" >17 Uhr</option><option value="18" >18 Uhr</option><option value="19" >19 Uhr</option> <option value="20">20 Uhr</option><option value="21">21 Uhr</option><option value="22" >22 Uhr</option><option value="23" >23 Uhr</option> </select> <select id="{{ uid(page, id) }}_mins_1" data-native-menu="false" multiple> <option data-placeholder="true">Minute</option> <option value="0" >00</option><option value="0" >05</option> <option value="10">10</option><option value="15">15</option> <option value="20">20</option><option value="25">25</option> <option value="30">30</option><option value="35">35</option> <option value="40">40</option><option value="45">45</option> <option value="50">50</option><option value="55">55</option> </select> </fieldset> <label for="{{ uid(page, id) }}_wday_0" class="select">Ausschalten jeden:</label> <fieldset data-role="controlgroup" data-type="horizontal" data-mini="true"> <select id="{{ uid(page, id) }}_wday_0" data-native-menu="false" multiple> <option data-placeholder="true">Tag</option> <option value="0">Montag</option> <option value="1">Dienstag</option> <option value="2">Mittwoch</option> <option value="3">Donnerstag</option> <option value="4">Freitag</option> <option value="5">Samstag</option> <option value="6">Sonntag</option> </select> <select id="{{ uid(page, id) }}_hour_0" data-native-menu="false" multiple> <option data-placeholder="true">Stunde</option> <option value="0" >00 Uhr</option><option value="1" >01 Uhr</option><option value="2" >02 Uhr</option><option value="3" >03 Uhr</option><option value="4" >04 Uhr</option> <option value="5" >05 Uhr</option><option value="6" >06 Uhr</option><option value="7" >07 Uhr</option><option value="8" >08 Uhr</option><option value="9" >09 Uhr</option> <option value="10">10 Uhr</option><option value="11">11 Uhr</option><option value="12" >12 Uhr</option><option value="13" >13 Uhr</option><option value="14" >14 Uhr</option> <option value="15">15 Uhr</option><option value="16">16 Uhr</option><option value="17" >17 Uhr</option><option value="18" >18 Uhr</option><option value="19" >19 Uhr</option> <option value="20">20 Uhr</option><option value="21">21 Uhr</option><option value="22" >22 Uhr</option><option value="23" >23 Uhr</option> </select> <select id="{{ uid(page, id) }}_mins_0" data-native-menu="false" multiple> <option data-placeholder="true">Minute</option> <option value="0" >00</option><option value="0" >05</option> <option value="10">10</option><option value="15">15</option> <option value="20">20</option><option value="25">25</option> <option value="30">30</option><option value="35">35</option> <option value="40">40</option><option value="45">45</option> <option value="50">50</option><option value="55">55</option> </select> </fieldset> </div> <a id="{{ uid(page, id) }}_set" data-widget="basic.crontab_set" data-name="zeitschaltuhr" data-val="{{ id }}" class="ui-midi" data-role="button" data-inline="true" data-iconpos="nopic"> <div>set</div> </a> {% endmacro %}
Code:
// ----- c r o n t a b ------------------------------------------------------------ // ---------------------------------------------------------------------------- // ----- basic.crontab ------------------------------------------------------- $(document).delegate('div[data-widget="basic.crontab"]', { 'init': function (event) { //* 'init' : Triggered from the widget (macro) itself to change it dynamically on startup. this.update(event, $(this).attr('data-val') ); }, 'update': function (event, response) { //* 'udate': Triggered through widget.update if a item has been changed. // DEBUG: console.log("[basic.crontab] update response :" + response[0] ); cr = response[0].split(' | '); // DEBUG: console.log("[basic.crontab] update split cr :" + cr ); cr1 = cr[0].split(' =')[0].split('_'); cr0 = cr[1].split(' =')[0].split('_'); // DEBUG: console.log("[basic.crontab] update cr1, cr0 :" + cr1 + " , " +cr0 ); mins_1 = cr1[0].split(','); mins_0 = cr0[0].split(','); hour_1 = cr1[1].split(','); hour_0 = cr0[1].split(','); wday_1 = cr1[2].split(','); wday_0 = cr0[2].split(','); // DEBUG: console.log("[basic.crontab] update crontab EIN: m"+mins_1+" h"+hour_1+" d"+wday_1); console.log("[basic.crontab] update crontab AUS: m"+mins_0+" h"+hour_0+" d"+wday_0); if (mins_1 != "*") { $('#' + this.id + '_mins_1').val(mins_1)}; $('#' + this.id + '_mins_1').selectmenu('refresh', true); if (hour_1 != "*") { $('#' + this.id + '_hour_1').val(hour_1)}; $('#' + this.id + '_hour_1').selectmenu('refresh', true); if (wday_1 != "*") { $('#' + this.id + '_wday_1').val(wday_1)}; $('#' + this.id + '_wday_1').selectmenu('refresh', true); if (mins_0 != "*") { $('#' + this.id + '_mins_0').val(mins_0)}; $('#' + this.id + '_mins_0').selectmenu('refresh', true); if (hour_0 != "*") { $('#' + this.id + '_hour_0').val(hour_0)}; $('#' + this.id + '_hour_0').selectmenu('refresh', true); if (wday_0 != "*") { $('#' + this.id + '_wday_0').val(wday_0)}; $('#' + this.id + '_wday_0').selectmenu('refresh', true); }, 'change': function (event) { //* Standard jquery-mobile events, triggered from the framework. var wday_1 = $('#' + this.id + '_wday_1').val(); wday_1 = (wday_1) ? wday_1 : "*"; var hour_1 = $('#' + this.id + '_hour_1').val(); hour_1 = (hour_1) ? hour_1 : "*"; var mins_1 = $('#' + this.id + '_mins_1').val(); mins_1 = (mins_1) ? mins_1 : "*"; // DEBUG: console.log("[basic.crontab] EIN change '" + this.id + "':" + wday_1 + ":" + hour_1 + ":" + mins_1 ); var wday_0 = $('#' + this.id + '_wday_0').val(); wday_0 = (wday_0) ? wday_0 : "*"; var hour_0 = $('#' + this.id + '_hour_0').val(); hour_0 = (hour_0) ? hour_0 : "*"; var mins_0 = $('#' + this.id + '_mins_0').val(); mins_0 = (mins_0) ? mins_0 : "*"; // DEBUG: console.log("[basic.crontab] AUS change '" + this.id + "':" + wday_0 + ":" + hour_0 + ":" + mins_0 ); var crontab_1 = mins_1 + "_" + hour_1 + "_" + wday_1 + '_*'; var crontab_0 = mins_0 + "_" + hour_0 + "_" + wday_0 + '_*'; io.write($(this).attr('data-item'), crontab_1 + ' = 1 | ' + crontab_0 + " = 0" ); } }); $(document).delegate('a[data-widget="basic.crontab_set"]', { 'click': function (event) { io.trigger($(this).attr('data-name'), $(this).attr('data-val')); } });
Kommentar