Thomas Skrevet 9. april 2018 Skrevet 9. april 2018 (endret) Jeg har programmert en Xiaomi Mi Magic Cube Controller. Den får en status f.eks 1002. Side 1 opp, kommer fra side 3. 2004 side 2 opp, kommer fra side 4 Noen som har tips til hvordan jeg kan forenkle dette scriptet ? Må altså lage 6 slike for å dekke alle sider Quote - alias: 'Cube Side 1' initial_state: True trigger: - platform: event event_type: deconz_event event_data: id: lumisensor_cube event: 1001 - platform: event event_type: deconz_event event_data: id: lumisensor_cube event: 1002 - platform: event event_type: deconz_event event_data: id: lumisensor_cube event: 1003 - platform: event event_type: deconz_event event_data: id: lumisensor_cube event: 1004 - platform: event event_type: deconz_event event_data: id: lumisensor_cube event: 1005 - platform: event event_type: deconz_event event_data: id: lumisensor_cube event: 1006 action: - service: input_select.select_option data: entity_id: input_select.cube_select option: 'Side 1' Endret 9. april 2018 av Thomas Siter
Moskus Skrevet 9. april 2018 Skrevet 9. april 2018 Jeg har gjort tilsvarende i i HS, men vet ikke hvilke scriptingmuligheter du har. Det holder å sjekke det første tallet i strengen, f.eks. 1003 og 1004 betyr begge "snudd til side 1", men du trenger jo ikke sjekke hvilken side den kom fra. Siter
LaStrada Skrevet 10. april 2018 Skrevet 10. april 2018 Ikke prøvd denne selv, men bør være mulig å gjøre noe lignende: - alias: 'Cube Side 1' trigger: - platform: event event_type: deconz_event event_data: id: lumisensor_cube # event: 1001 condition: - condition: template value_template: >- # Sjekk om event inneholder "100" (ignorere siste siffer) # NB! Ikke testet selv. Har aldri hentet ut data fra eventer tidligere {% if '100' in trigger.event.data["event"] %} True {% else %} False {% endif %} action: - service: input_select.select_option data: entity_id: input_select.cube_select option: 'Side 1' Du skal kunne søke etter "100", "200" eller lignende, dvs du kan ignorere siste siffer. https://community.home-assistant.io/t/use-event-data-from-telegram-in-action/16901/3 Et eksempel jeg fant ved googling, det er mulig å bruke event data (trigger) i condition og/eller action. Personlig har jeg begynt å skrive python-script for litt tyngre automasjoner, fordi det er et mye kraftigere verktøy enn yaml-cofig. Siter
Thomas Skrevet 10. april 2018 Forfatter Skrevet 10. april 2018 (endret) Gikk ikke helt. Får følgende feilmelding: Quote 2018-04-10 23:21:21 DEBUG (MainThread) [pydeconz.websocket] Websocket data: b'\x81s{"e":"changed","id":"2","r":"sensors","state":{"buttonevent":1003,"lastupdated":"2018-04-10T21:21:21"},"t":"event"}' 2018-04-10 23:21:21 DEBUG (MainThread) [pydeconz.deconzdevice] lumi.sensor_cube: update buttonevent with 1003 2018-04-10 23:21:21 DEBUG (MainThread) [pydeconz.deconzdevice] lumi.sensor_cube: update lastupdated with 2018-04-10T21:21:21 2018-04-10 23:21:21 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/home/thomas/homeassistant/lib/python3.6/site-packages/homeassistant/components/automation/__init__.py", line 335, in async_trigger if skip_condition or self._cond_func(variables): File "/home/thomas/homeassistant/lib/python3.6/site-packages/homeassistant/components/automation/__init__.py", line 444, in if_action return all(check(hass, variables) for check in checks) File "/home/thomas/homeassistant/lib/python3.6/site-packages/homeassistant/components/automation/__init__.py", line 444, in <genexpr> return all(check(hass, variables) for check in checks) File "/home/thomas/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/condition.py", line 317, in template_if return async_template(hass, value_template, variables) File "/home/thomas/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/condition.py", line 299, in async_template value = value_template.async_render(variables) File "/home/thomas/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/template.py", line 132, in async_render return self._compiled.render(kwargs).strip() File "/home/thomas/homeassistant/lib/python3.6/site-packages/jinja2/asyncsupport.py", line 76, in render return original_render(self, *args, **kwargs) File "/home/thomas/homeassistant/lib/python3.6/site-packages/jinja2/environment.py", line 1008, in render return self.environment.handle_exception(exc_info, True) File "/home/thomas/homeassistant/lib/python3.6/site-packages/jinja2/environment.py", line 780, in handle_exception reraise(exc_type, exc_value, tb) File "/home/thomas/homeassistant/lib/python3.6/site-packages/jinja2/_compat.py", line 37, in reraise raise value.with_traceback(tb) File "<template>", line 1, in top-level template code TypeError: argument of type 'int' is not iterable Har tenkt på pyhon-script jeg også, men har liksom ikke kommet igang. Spørs om dette er en anledning til å begynne :-) Endret 10. april 2018 av Thomas Siter
Thomas Skrevet 11. april 2018 Forfatter Skrevet 11. april 2018 11 hours ago, LaStrada said: Personlig har jeg begynt å skrive python-script for litt tyngre automasjoner, fordi det er et mye kraftigere verktøy enn yaml-cofig. HVIS denne funger (får ikke testet før i kveld), så har jeg spart meg for vanvittig mange linjer :-) Takk for tips Quote - alias: 'Cube 1' trigger: - platform: event event_type: deconz_event event_data: id: lumisensor_cube action: - service: python_script.xiaomi_cube data_template: cube: 1 event: '{{ trigger.event.data.event }}' Quote cube = int(data.get('cube')) value = int(data.get('event')) x = int(str(value)[0]) y = int(str(value)[3]) if cube == 1: if value == 7000: logger.info("xiaomi_cube_" + str(cube) + " woke up") elif value == 7007: logger.info("xiaomi_cube_" + str(cube) + " shake") elif y == 0: logger.info("xiaomi_cube_" + str(cube) + " push") elif x == y: logger.info("xiaomi_cube_" + str(cube) + " double tap") elif y == 7 - x: logger.info("xiaomi_cube_" + str(cube) + " 180 flip") elif x == 1: logger.info("xiaomi_cube_" + str(cube) + " Side 1") hass.services.call('input_select','select_option',{'entity_id': 'input_select.cube_select', 'option': 'Side 1'}) elif x == 2: logger.info("xiaomi_cube_" + str(cube) + " Side 2") hass.services.call('input_select','select_option',{'entity_id': 'input_select.cube_select', 'option': 'Side 2'}) elif x == 3: logger.info("xiaomi_cube_" + str(cube) + " Side 3") hass.services.call('input_select','select_option',{'entity_id': 'input_select.cube_select', 'option': 'Side 3'}) elif x == 4: logger.info("xiaomi_cube_" + str(cube) + " Side 4") hass.services.call('input_select','select_option',{'entity_id': 'input_select.cube_select', 'option': 'Side 4'}) elif x == 5: logger.info("xiaomi_cube_" + str(cube) + " Side 5") hass.services.call('input_select','select_option',{'entity_id': 'input_select.cube_select', 'option': 'Side 6'}) elif x == 6: logger.info("xiaomi_cube_" + str(cube) + " Side 6") hass.services.call('input_select','select_option',{'entity_id': 'input_select.cube_select', 'option': 'Side 6'}) cube: 1 er egentlig bare for å kunne bruke scriptet mot flere cube'r Siter
Anbefalte innlegg
Bli med i samtalen
Du kan publisere innhold nå og registrere deg senere. Hvis du har en konto, logg inn nå for å poste med kontoen din.