Hallo Morg,
tut nich:
2021-01-17 15:03:54 ERROR logics.visual_alarm Logic: logics.visual_alarm, File: /usr/local/smarthome/logics/blinker.py, Line: 49, Method: <module>, Exception: isinstance expected 2 arguments, got 1
> Traceback (most recent call last):
> File "/usr/local/smarthome/lib/scheduler.py", line 590, in _task
> exec(obj.bytecode)
> File "/usr/local/smarthome/logics/blinker.py", line 49, in <module>
> if not isinstance(blink_items_anticyclic):
> TypeError: isinstance expected 2 arguments, got 1
Gruß Jürgen
Ankündigung
Einklappen
Keine Ankündigung bisher.
Blinker.py konfigurieren
Einklappen
X
-
Code:#!/usr/bin/env python3 # vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab # LOGIC config # ------------------------------------------------------- # visual_alarm: # filename: blinker.py # watch_item: HOME.alarm.action.blinkinglight # set_items_cyclic: # - AUSSEN.south.light.outer # - AUSSEN.west.light.outer # set_items_anticyclic: # - AUSSEN.south.light.inner # - AUSSEN.east.light.door # - AUSSEN.west.light.nested # set_blink_cycles: -1 ' -1: endless # set_blink_interval: 2 # dry_run: 0 control_item_name = trigger['source'] control_item = sh.return_item(control_item_name) triggered_by = trigger['by'] if control_item is not None: logger.info(f'LOGIC blinker.py: {logic.name} triggered from source {control_item_name} by {triggered_by}') # control_item_active = trigger['value'] control_item_active = control_item() # set parameters from logic config blink_items_cyclic = [] if hasattr(logic, 'set_items_cyclic'): blink_items_cyclic = logic.set_items_cyclic if isinstance(blink_items_cyclic, str): blink_items_cyclic = [blink_items_cyclic, ] # do we have blink items? if not isinstance(blink_items_cyclic, list) or len(blink_items_cyclic) == 0: logger.info('LOGIC blinker.py: error, no cyclic blink items set. Aborting') else: blink_items_anticyclic = [] if hasattr(logic, 'set_items_anticyclic'): blink_items_anticyclic = logic.set_items_anticyclic if isinstance(blink_items_anticyclic, str): blink_items_anticyclic = [blink_items_anticyclic, ] # did we get strange data? if not isinstance(blink_items_anticyclic): blink_items_anticyclic = [] if hasattr(logic, 'set_blink_cycles'): blink_cycles = int(logic.set_blink_cycles) else: blink_cycles = 2 logger.info(f'LOGIC blinker.py: no blink cycles set, setting to default: {blink_cycles}') if hasattr(logic, 'set_blink_interval'): blink_interval = int(logic.set_blink_interval) else: blink_interval = 2 logger.info(f'LOGIC blinker.py: no blink interval set, setting to default: {blink_interval}') if hasattr(logic, 'dry_run'): dry_run = (int(logic.dry_run) > 0) else: dry_run = False if control_item_active: # first call? if not hasattr(logic, 'blink_init'): logger.info(f'LOGIC blinker.py: initiating {blink_cycles} blinks for {len(blink_items_cyclic)} cyclic and {len(blink_items_anticyclic)} anti-cyclic items') logic.blink_init = True blink_items = blink_items_cyclic + blink_items_anticyclic if len(blink_items) > 0: # SAVE item states logic.saved_items = {} for item_name in blink_items: item = sh.return_item(item_name) logic.saved_items[item_name] = item() logger.info(f'LOGIC blinker.py: save {item_name} = {item()}') if dry_run: logger.warn('LOGIC blinker.py: test mode, dry run active') else: logger.warn('LOGIC blinker.py: no blink items set') # prepare blink if hasattr(logic, 'blink_value'): logic.blink_value = not logic.blink_value else: logic.blink_value = True if hasattr(logic, 'blink_countdown'): logic.blink_countdown -= 1 else: logic.blink_countdown = blink_cycles # any blinks left? if logic.blink_countdown > 0 or blink_cycles == -1: if blink_cycles == -1: logger.info('LOGIC blinker.py BLINK (endless)') else: logger.info(f'LOGIC blinker.py BLINK ({logic.blink_countdown} cycles remaining)') # set all cyclic items for item_name in blink_items_cyclic: item = sh.return_item(item_name) logger.info(f'LOGIC blinker.py SET {item_name} to {logic.blink_value}') if not dry_run: item(logic.blink_value) # set all anti-cyclic items for item_name in blink_items_anticyclic: item = sh.return_item(item_name) logger.info(f'LOGIC blinker.py SET {item_name} to {not logic.blink_value}') if not dry_run: item(not logic.blink_value) sh.trigger(f'logics.{logic.name}', by=trigger['by'], source=trigger['source'], value=trigger['value'], dt=sh.now() + datetime.timedelta(seconds=blink_interval)) else: logger.info('LOGIC blinker.py countdown finished, set control item to False') control_item(False) # this triggers logic again! else: logger.info('LOGIC blinker.py control item set to false: stop blink logic, restore saved item values') # RESTORE item states if hasattr(logic, 'saved_items'): for item_name in logic.saved_items: item = sh.return_item(item_name) value = logic.saved_items[item_name] logger.info(f'LOGIC blinker.py: restore {item_name} = {item()}') if not dry_run: item(value) # reset persistent values if hasattr(logic, 'saved_items'): delattr(logic, 'saved_items') if hasattr(logic, 'blink_countdown'): delattr(logic, 'blink_countdown') if hasattr(logic, 'blink_value'): delattr(logic, 'blink_value') if hasattr(logic, 'blink_init'): delattr(logic, 'blink_init') else: logger.info('LOGIC blinker.py triggered without source... ignoring...')
Einen Kommentar schreiben:
-
Ups. Danke für den Input bzgl. des letzten Else, mag sein, dass das "verloren" gegangen ist.
Es muss heißen "if not isinstance(blink_items_cyclic, list) or..."
Einen Kommentar schreiben:
-
Hallo Morg,
wird nicht geladen, die letzte Else am Ende wird angemeckert...
Habe den mal nach rechts unte das letzte if eingerückt, dann wird das Plugin geladen,
klappt aber nicht:
Code:2021-01-17 11:36:35 ERROR logics.visual_alarm Logic: logics.visual_alarm, File: /usr/local/smarthome/logics/blinker.py, Line: 38, Method: <module>, Exception: isinstance expected 2 arguments, got 1 > Traceback (most recent call last): > File "/usr/local/smarthome/lib/scheduler.py", line 590, in _task > exec(obj.bytecode) > File "/usr/local/smarthome/logics/blinker.py", line 38, in <module> > if not isinstance(blink_items_cyclic) or len(blink_items_cyclic) == 0: > TypeError: isinstance expected 2 arguments, got 1
Gruß JürgenZuletzt geändert von Jürgen; 17.01.2021, 11:38.
Einen Kommentar schreiben:
-
Probier mal den Code. Habe ich jetzt nicht getestet, aber ich hoffe, ich habe keine Fehler reingebaut
Verlangt kein anticyclic und geht damit um, wenn da Unsinn drin steht.
Für einen zweiten Blinker müsste es eigentlich reichen, eine zweite Logik mit derselben Datei zu konfigurieren, die dann entsprechend eigene Einstellungen hat....Code:#!/usr/bin/env python3 # vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab # LOGIC config # ------------------------------------------------------- # visual_alarm: # filename: blinker.py # watch_item: HOME.alarm.action.blinkinglight # set_items_cyclic: # - AUSSEN.south.light.outer # - AUSSEN.west.light.outer # set_items_anticyclic: # - AUSSEN.south.light.inner # - AUSSEN.east.light.door # - AUSSEN.west.light.nested # set_blink_cycles: -1 ' -1: endless # set_blink_interval: 2 # dry_run: 0 control_item_name = trigger['source'] control_item = sh.return_item(control_item_name) triggered_by = trigger['by'] if control_item is not None: logger.info(f'LOGIC blinker.py: {logic.name} triggered from source {control_item_name} by {triggered_by}') # control_item_active = trigger['value'] control_item_active = control_item() # set parameters from logic config blink_items_cyclic = [] if hasattr(logic, 'set_items_cyclic'): blink_items_cyclic = logic.set_items_cyclic if isinstance(blink_items_cyclic, str): blink_items_cyclic = [blink_items_cyclic, ] # do we have blink items? if not isinstance(blink_items_cyclic) or len(blink_items_cyclic) == 0: logger.info('LOGIC blinker.py: error, no cyclic blink items set. Aborting') else: blink_items_anticyclic = [] if hasattr(logic, 'set_items_anticyclic'): blink_items_anticyclic = logic.set_items_anticyclic if isinstance(blink_items_anticyclic, str): blink_items_anticyclic = [blink_items_anticyclic, ] # did we get strange data? if not isinstance(blink_items_anticyclic): blink_items_anticyclic = [] if hasattr(logic, 'set_blink_cycles'): blink_cycles = int(logic.set_blink_cycles) else: blink_cycles = 2 logger.info(f'LOGIC blinker.py: no blink cycles set, setting to default: {blink_cycles}') if hasattr(logic, 'set_blink_interval'): blink_interval = int(logic.set_blink_interval) else: blink_interval = 2 logger.info(f'LOGIC blinker.py: no blink interval set, setting to default: {blink_interval}') if hasattr(logic, 'dry_run'): dry_run = (int(logic.dry_run) > 0) else: dry_run = False if control_item_active: # first call? if not hasattr(logic, 'blink_init'): logger.info(f'LOGIC blinker.py: initiating {blink_cycles} blinks for {len(blink_items_cyclic)} cyclic and {len(blink_items_anticyclic)} anti-cyclic items') logic.blink_init = True blink_items = blink_items_cyclic + blink_items_anticyclic if len(blink_items) > 0: # SAVE item states logic.saved_items = {} for item_name in blink_items: item = sh.return_item(item_name) logic.saved_items[item_name] = item() logger.info(f'LOGIC blinker.py: save {item_name} = {item()}') if dry_run: logger.warn('LOGIC blinker.py: test mode, dry run active') else: logger.warn('LOGIC blinker.py: no blink items set') # prepare blink if hasattr(logic, 'blink_value'): logic.blink_value = not logic.blink_value else: logic.blink_value = True if hasattr(logic, 'blink_countdown'): logic.blink_countdown -= 1 else: logic.blink_countdown = blink_cycles # any blinks left? if logic.blink_countdown > 0 or blink_cycles == -1: if blink_cycles == -1: logger.info('LOGIC blinker.py BLINK (endless)') else: logger.info(f'LOGIC blinker.py BLINK ({logic.blink_countdown} cycles remaining)') # set all cyclic items for item_name in blink_items_cyclic: item = sh.return_item(item_name) logger.info(f'LOGIC blinker.py SET {item_name} to {logic.blink_value}') if not dry_run: item(logic.blink_value) # set all anti-cyclic items for item_name in blink_items_anticyclic: item = sh.return_item(item_name) logger.info(f'LOGIC blinker.py SET {item_name} to {not logic.blink_value}') if not dry_run: item(not logic.blink_value) sh.trigger(f'logics.{logic.name}', by=trigger['by'], source=trigger['source'], value=trigger['value'], dt=sh.now() + datetime.timedelta(seconds=blink_interval)) else: logger.info('LOGIC blinker.py countdown finished, set control item to False') control_item(False) # this triggers logic again! else: logger.info('LOGIC blinker.py control item set to false: stop blink logic, restore saved item values') # RESTORE item states if hasattr(logic, 'saved_items'): for item_name in logic.saved_items: item = sh.return_item(item_name) value = logic.saved_items[item_name] logger.info(f'LOGIC blinker.py: restore {item_name} = {item()}') if not dry_run: item(value) # reset persistent values if hasattr(logic, 'saved_items'): delattr(logic, 'saved_items') if hasattr(logic, 'blink_countdown'): delattr(logic, 'blink_countdown') if hasattr(logic, 'blink_value'): delattr(logic, 'blink_value') if hasattr(logic, 'blink_init'): delattr(logic, 'blink_init') else: logger.info('LOGIC blinker.py triggered without source... ignoring...')
Einen Kommentar schreiben:
-
Hallo Morg,
- NONE
klappt nicht:
> File "/usr/local/smarthome/logics/blinker.py", line 68, in <module>
> logic.saved_items[item_name] = item()
> TypeError: 'NoneType' object is not callable
: NONE
auch nicht:
> File "/usr/local/smarthome/logics/blinker.py", line 62, in <module>
> blink_items = blink_items_cyclic + blink_items_anticyclic
> TypeError: can only concatenate list (not "str") to list
- []
> File "/usr/local/smarthome/logics/blinker.py", line 68, in <module>
> logic.saved_items[item_name] = item()
> TypeError: 'NoneType' object is not callable
Noch jemand ne Idee?
Ich habe jetzt ein Dummy Device definiert, nun schaltet sich aber auch immer mein WatchItem nach Ende des Blinkens wieder aus :-(
Ich mach erstmal Schluss, das wird heute nix mehr :-(
Gruß Jürgen
Einen Kommentar schreiben:
-
Du könntest auch versuchen:
set_items_anticyclic: NONE
oder
set_items_anticyclic: []
Dann hat er den Parameter, im zweiten Fall sogar ne Liste und dann - mal schauen.
Einen Kommentar schreiben:
-
Hallo Andre,
perfekt! Die Else nach links und alles OK. Hab ich aber so aus der Doku übernommen. :-)
Bleibt noch die Frage, wie ich den einen 2. Blinker realisiere...
Gruß Jürgen
Einen Kommentar schreiben:
-
Hi Jürgen ,
ich vermute im Beispiel ist die Einrückung verrutscht :
Beispiel :
ich würde vermuten richtig wäre :Code:if not hasattr(logic, 'blink_init'): logger.info("LOGIC blinker.py: initiating {0} blinks for {1} cyclic and {2} anti-cyclic items".format(blink_cycles, len(blink_items_cyclic), len(blink_items_anticyclic))) logic.blink_init = True blink_items = blink_items_cyclic + blink_items_anticyclic if len(blink_items) > 0: # SAVE item states logic.saved_items = {} for item_name in blink_items: item = sh.return_item(item_name) logic.saved_items[item_name] = item() logger.info("LOGIC blinker.py: save {0} = {1}".format(item_name, item())) if dry_run == True: logger.warn("LOGIC blinker.py: test mode, dry run active") else: logger.warn("LOGIC blinker.py: no blink items set")
Ich interpretiere die Meldung "LOGIC blinker.py: no blink items set" soll nur ausgegeben werden wennCode:if not hasattr(logic, 'blink_init'): logger.info("LOGIC blinker.py: initiating {0} blinks for {1} cyclic and {2} anti-cyclic items".format(blink_cycles, len(blink_items_cyclic), len(blink_items_anticyclic))) logic.blink_init = True blink_items = blink_items_cyclic + blink_items_anticyclic if len(blink_items) > 0: # SAVE item states logic.saved_items = {} for item_name in blink_items: item = sh.return_item(item_name) logic.saved_items[item_name] = item() logger.info("LOGIC blinker.py: save {0} = {1}".format(item_name, item())) [MARKIEREN] if dry_run == True: logger.warn("LOGIC blinker.py: test mode, dry run active")[/MARKIEREN] else: logger.warn("LOGIC blinker.py: no blink items set")Die "Dryrun"-Meldung soll ausgegeben werden wennCode:len(blink_items) <= 0
undCode:len(blink_items) > 0
Gruss AndreCode:dry_run == True
Einen Kommentar schreiben:
-
Hallo Morg,
Done, geht auch nicht, den Parameter will er haben:
2021-01-16 17:01:06 ERROR logics.visual_alarm Logic: logics.visual_alarm, File: /usr/local/smarthome/logics/blinker.py, Line: 59, Method: <module>, Exception: name 'blink_items_anticyclic' is not defined
> Traceback (most recent call last):
> File "/usr/local/smarthome/lib/scheduler.py", line 590, in _task
> exec(obj.bytecode)
> File "/usr/local/smarthome/logics/blinker.py", line 59, in <module>
> logger.info("LOGIC blinker.py: initiating {0} blinks for {1} cyclic and {2} anti-cyclic items".format(blink_cycles, len(blink_items_cyclic), len(blink_items_anticyclic)))
> NameError: name 'blink_items_anticyclic' is not defined
2021-01-16 17:01:17 ERROR logics.visual_alarm Logic: logics.visual_alarm, File: /usr/local/smarthome/logics/blinker.py, Line: 59, Method: <module>, Exception: name 'blink_items_anticyclic' is not defined
> Traceback (most recent call last):
> File "/usr/local/smarthome/lib/scheduler.py", line 590, in _task
> exec(obj.bytecode)
> File "/usr/local/smarthome/logics/blinker.py", line 59, in <module>
> logger.info("LOGIC blinker.py: initiating {0} blinks for {1} cyclic and {2} anti-cyclic items".format(blink_cycles, len(blink_items_cyclic), len(blink_items_anticyclic)))
> NameError: name 'blink_items_anticyclic' is not defined
Aber mit einem anderen Ziel funktioniert es:
set_items_anticyclic:
- Erdgeschoss.Arbeitszimmer.Licht.Schreibtischlicht
Nun will ich aber nicht zwingend etwas zusätzlich schalten, also muss ich wohl ein Dummy Item anlegen, oder?
Noch eine Frage:
Wenn ich einen zweiten Blinker benötige, lege ich dann nach gleichem Muster eine Blinker2.py an?
In der Config sehe ich keine sprechende Möglichkeit für ein zweites überwachtes Item und die entsprechenden Ausgaben.
Nachtrag:
Obwohl es bei zwei Items funktioniert, kommt bei jeder Sequenz ein Syslog Eintrag:
2021-01-16 17:29:12 WARNING logics.visual_alarm LOGIC blinker.py: no blink items set
Laut Code kommt das immer, wenn der dry mode nicht gesetzt ist, macht doch keinen Sinn...
GrußPHP-Code:if dry_run == True: logger.warn("LOGIC blinker.py: test mode, dry run active")
else: logger.warn("LOGIC blinker.py: no blink items set")
Jürgen
Zuletzt geändert von Jürgen; 16.01.2021, 17:35.
Einen Kommentar schreiben:
-
Kommentiere mal set_items_anticyclic aus. Das ist eine leere Liste und funktioniert so nicht.
Einen Kommentar schreiben:
-
Blinker.py konfigurieren
Hallo zusammen,
ich versuche das Blinker.py (https://www.smarthomeng.de/blinken-per-logik) zu nutzen, klappt leider nicht:
Soll: Wenn Deckenlicht eingeschaltet wird, soll Schranklicht 4x blinken (Macht keinen Sinn, ist aber einfach zu kontrollieren ;-) )
Das blinker.py habe ich als Text von der Webseite kopiert und im Verzeichnis /logics/blinker.py abgelegt
Hier meine /etc/logic.yaml:
Das Admin Tool zeigt beide Items als bool an:Code:visual_alarm: filename: blinker.py watch_item: Erdgeschoss.Arbeitszimmer.Licht.Deckenlicht set_items_cyclic: - Erdgeschoss.Arbeitszimmer.Licht.Schranklicht # - AUSSEN.south.light.outer # - AUSSEN.west.light.outer set_items_anticyclic: # - AUSSEN.south.light.inner # - AUSSEN.east.light.door # - AUSSEN.west.light.nested set_blink_cycles: 4 # -1 for endless loop set_blink_interval: 4 dry_run: 0
Item Pfad Erdgeschoss.Arbeitszimmer.Licht.Schranklicht Item Name Erdgeschoss.Arbeitszimmer.Licht.Schranklicht Datentyp bool Hier der Fehler im Logfile, den ich leider nicht verstehe:Item Pfad Erdgeschoss.Arbeitszimmer.Licht.Deckenlicht Item Name Erdgeschoss.Arbeitszimmer.Licht.Deckenlicht Datentyp bool
2021-01-16 15:50:36 ERROR logics.visual_alarm Logic: logics.visual_alarm, File: /usr/local/smarthome/logics/blinker.py, Line: 62, Method: <module>, Exception: can only concatenate list (not "str") to list
> Traceback (most recent call last):
> File "/usr/local/smarthome/lib/scheduler.py", line 590, in _task
> exec(obj.bytecode)
> File "/usr/local/smarthome/logics/blinker.py", line 62, in <module>
> blink_items = blink_items_cyclic + blink_items_anticyclic
> TypeError: can only concatenate list (not "str") to list
2021-01-16 15:50:53 ERROR logics.visual_alarm Logic: logics.visual_alarm, File: /usr/local/smarthome/logics/blinker.py, Line: 62, Method: <module>, Exception: can only concatenate list (not "str") to list
> Traceback (most recent call last):
> File "/usr/local/smarthome/lib/scheduler.py", line 590, in _task
> exec(obj.bytecode)
> File "/usr/local/smarthome/logics/blinker.py", line 62, in <module>
> blink_items = blink_items_cyclic + blink_items_anticyclic
> TypeError: can only concatenate list (not "str") to list
Im Admin Tool unter Logiken wir das Watch Item aufgeführt:
Watch Items
Erdgeschoss.Arbeitszimmer.Licht.Deckenlicht
Blinker.py wird angezeigt.
Hat jemand eine Idee?
Gruß JürgenZuletzt geändert von Jürgen; 16.01.2021, 22:49.Stichworte: -


Einen Kommentar schreiben: