diff --git a/.gitignore b/.gitignore index 38b77e3..763987f 100644 --- a/.gitignore +++ b/.gitignore @@ -11,5 +11,6 @@ packages/**/*_secret.yaml !/appdaemon/apps *.json *.hidden.* +!python_scripts !/lovelace/ diff --git a/appdaemon/apps/vacuum.py b/appdaemon/apps/vacuum.py new file mode 100644 index 0000000..e68a90a --- /dev/null +++ b/appdaemon/apps/vacuum.py @@ -0,0 +1,34 @@ +from entities import Entities + +class Vacuum(Entities): + def initialize(self): + super().initialize() + self.entity_id = self.args['entity_id'] + + self.run_in(self._setup, 1) + + def _setup(self, kwargs): + for zone in self.args['zones']: + e = dict(self.args['zones'][zone]) + name = f'switch.vacuum_{zone}' + self.register_entity(zone, name, True, "off", e) + + self.listen_event(self.zone, 'VACUUM_ZONE') + self.listen_event(self.all, 'VACUUM_ALL') + self.listen_event(self.service, 'VACUUM_SERVICE') + self.listen_event(self.home, 'VACUUM_HOME') + + def zone(self, ev, data, kwargs): + areas = [] + for zone in self.args['zones']: + if self.e[zone].state == "on": + areas.append(self.e[zone].attr['area']) + + self.call_service("vacuum/xiaomi_clean_zone", repeats = 1, zone = areas) + + def all(self, ev, data, kwargs): + self.call_service("vacuum/start") + def service(self, ev, data, kwargs): + self.call_service("vacuum/send_command", entity_id = self.entity_id, command = 'app_goto_target', params = self.args['empty_spot']) + def home(self, ev, data, kwargs): + self.call_service("vacuum/return_to_base", entity_id = self.entity_id) diff --git a/appdaemon/apps/vacuum.yaml b/appdaemon/apps/vacuum.yaml new file mode 100644 index 0000000..661c0f6 --- /dev/null +++ b/appdaemon/apps/vacuum.yaml @@ -0,0 +1,29 @@ +vacuum: + module: vacuum + class: Vacuum + global_dependencies: + - base + - entities + + entity_id: vacuum.xiaomi_vacuum_cleaner + + empty_spot: [26000, 26000] + + zones: + kitchen: + # Left, bottom, right, top + area: [23200, 21000, 27500, 25100] + friendly_name: Köket + hall: + area: [23200, 25300, 27500, 28000] + friendly_name: Hallen + livingroom: + area: [19000, 24000, 23000, 31200] + friendly_name: Vardagsrum + bedroom: + area: [19000, 31500, 23500, 35500] + friendly_name: Sovrum + office: + area: [23300, 31000, 27500, 35500] + friendly_name: Kontoret + diff --git a/configuration.yaml b/configuration.yaml index e062add..25ed019 100644 --- a/configuration.yaml +++ b/configuration.yaml @@ -28,3 +28,5 @@ http: trusted_proxies: !secret proxy_hosts cloud: + +python_script: diff --git a/lovelace/vacuum_card.yaml b/lovelace/vacuum_card.yaml new file mode 100644 index 0000000..841b2b0 --- /dev/null +++ b/lovelace/vacuum_card.yaml @@ -0,0 +1,45 @@ +type: vertical-stack +cards: + - type: custom:auto-entities + card: { type: entities } + filter: + include: + - entity_id: switch.vacuum_* + - type: horizontal-stack + cards: + - type: entity-button + entity: sun.sun + icon: mdi:broom + name: Städa + tap_action: + action: call-service + service: python_script.event + service_data: + event: VACUUM_ZONE + - type: entity-button + entity: sun.sun + icon: mdi:broom + name: Städa Allt + tap_action: + action: call-service + service: python_script.event + service_data: + event: VACUUM_ALL + - type: entity-button + entity: sun.sun + icon: mdi:wrench + name: Töm + tap_action: + action: call-service + service: python_script.event + service_data: + event: VACUUM_SERVICE + - type: entity-button + entity: sun.sun + icon: mdi:sleep + name: Vila + tap_action: + action: call-service + service: python_script.event + service_data: + event: VACUUM_HOME diff --git a/lovelace/views/dashboard_view.yaml b/lovelace/views/dashboard_view.yaml index fbbadd3..4af9e9d 100644 --- a/lovelace/views/dashboard_view.yaml +++ b/lovelace/views/dashboard_view.yaml @@ -5,14 +5,7 @@ panel: true popup_cards: vacuum.xiaomi_vacuum_cleaner: title: Dammsugare - card: - type: entities - entities: - - vacuum.xiaomi_vacuum_cleaner - - script.vacuum_home - - script.vacuum_empty - - script.vacuum_daily - - script.vacuum_all + card: !include vacuum_card.yaml cards: - type: custom:layout-card layout: vertical diff --git a/python_scripts/event.py b/python_scripts/event.py new file mode 100644 index 0000000..17d3dcb --- /dev/null +++ b/python_scripts/event.py @@ -0,0 +1,4 @@ +ev = data.get('event', None) +ev_data = data.get('data', {}) +if ev: + hass.bus.fire(ev, ev_data)