Switch predictor for Home Assistant with AppDeamon

Overview

Home Assistant AppDeamon - Event predictor

"Buy Me A Coffee"

WORK IN PROGRESS - CURRENTLY NOT COMPLETE AND NOT WORK

This is an idea under development (when I have free time)

I am Italian, sorry for any mistakes in English.

I want to try it right now!

No, wait.

This is a program in Python that I'm making in my spare time and is currently unfinished.

To try it and possibly contribute (thanks!) these are the ingredients:

  • knowledge of Python

  • a working instance of Home Assistant

  • the appDeamon addon correctly installed and running

The idea (and the dream)

My goal (and dream) is for Home Assistant to decide autonomously when it is appropriate to activate a certain event, based on the history of one or more switches, relating the date and time and the status of other sensors. Based on the calculations performed, if the level of certainty is high it could directly activate the switch, or if it is low (uncertain) it could ask through Alexa (Amazon) if you want to proceed with the activation and based on the answer given it could even modify its data model.

Use case example

  • An automation is automatically created to start the robot vacuum cleaner when nobody is at home, the time slot is from 14:00 to 18:00, the balcony door is closed and the humidity is below 60%.

  • An automation is automatically created to turn on the television when someone is at home, it is between 20:00 and 22:00, dinner is being served, the temperature in the house is above 22°C and there is no upcoming appointment on the calendar.

  • Asked if you want coffee if the time slot is from 12:00 to 14:00, someone is at home, you have just finished having lunch, the temperature at home is below 25°C - if not, the model is modified

Warning: all these automatic automations are based on actions already performed previously, according to probabilistic calculations.

It is not foreseen that the system considers to ask or to execute actions in a completely spontaneous way.

Progress & ToDo

  • (OP#1) Getting the history of a specific switch in specified time period

  • (DF#1) Getting the history from influxdb

  • (OP#2) Getting the history of all connected sensors

  • Caching the history

  • (OP#3) get time slot from the history of the based on sensors

  • (OP#4) Filters the BaseSwitch periodOn data by excluding insignificant events

  • (OP#5) Save the model (and reuse for caching)

  • (OP#6) Listen of variation on baseOnSensor

  • (OP#7) Send an event to Home Assistant with the potential switch

  • (Thanks @Pirol62) consider the variation of time (season, year, ecc...)

  • Optimizing Code

  • Testing

  • more Testing :)

Operation diagram

  1. (OP#1) Getting the history of a specific switch (baseSwitch) in specified time period (by config)

  2. (OP#2) Getting the history of all connected sensors (basedOnSensor - declared on Config) in the time interval in which baseSwitch has been activated (on) since a time specified in configuration

  3. (OP#3) From the history of the various sensors (basedOnSensor), when they change state, group the times by rounding them to a value specified in the configuration, thus obtaining the day of the week, the hour, the minutes of the event and calculate the frequency of repetition

  4. (OP#4) Discard the data that are not satisfactory or because they are too few (by config)

  5. (OP#5) Save the model

  6. (OP#6) Listen to the variations of the basedOnSensor and compare them with the results of the model

  7. (OP#7) Send an event to Home Assistant with the potential switch to manage the probability of it happening. It will be in Home Assistant that will decide what to do, whether to activate the switch or ask the user if they want to activate it.

Problems and difficulties

  1. (DF#1) Unfortunately, I realized that I can't rely on HomeAssistant's history, because the save range for the data is very limited. I have to get the data from influxDB

Want to help? You are welcome!

This is and shall be an open, free and non-profit project; the goal is to create an automated system to manage situations in HomeAssistant.

Or, if you want to thank me for what I do by buying me a coffee:

"Buy Me A Coffee"

No one should and will ever make money from this project.

If you want to help me in any way (advice, code, etc...) you are welcome to do so and I really thank you very much! Use the tools that Github provides!

Comments
  • Handling of Predictor responses

    Handling of Predictor responses

    I would implement it like this: the event triggers an automation, which let alexa/google ask: You switched this entity by 90% during the last week. Do you want to switch it now? if yes a second question should be “shall I create an automation?” When yes, alexa never have to ask again.

    A second issue comes up when thinking about a yearly time period. The behavior changes i.e. over the seasons. In summertime a switch is changed at another time or never compared to winter. So the prediction has to be calculated over a long (at least a year) time period and will provide different results over this time. So my first suggestion, creating an automation, is not that good in a first state. Otherwise: Let alexa always ask questions can lead to annoying situations where alexa asks too often. Maybe, there should be the option to reduce this support only to a type of switches (light, covers, heating etc)

    enhancement 
    opened by Pirol62 4
  • Error on DB initialization

    Error on DB initialization

    On starting AppDeamon:

    2022-11-03 13:28:43.826007 INFO AppDaemon: Initializing app hass_myhomesmart using class main from module hass_myhomesmart 2022-11-03 13:28:43.913390 INFO hass_myhomesmart: DB ready: /conf/apps/MyHomeSmart-HASS-AppDeamon/db/entitystate_DB.db 2022-11-03 13:28:43.914414 INFO hass_myhomesmart: DB ready: causeeffect_DB.db 2022-11-03 13:28:43.931573 INFO hass_myhomesmart: ################################################################ 2022-11-03 13:28:43.932341 INFO hass_myhomesmart: ERROR in initialize:112 - [ 'NoneType' object is not iterable ] 2022-11-03 13:28:43.933604 INFO hass_myhomesmart: Previous message repeated 1 times 2022-11-03 13:28:43.933741 INFO hass_myhomesmart: Due to this error, MyHomeSmart cannot continue and must be restarted. 2022-11-03 13:28:43.934273 INFO hass_myhomesmart: ################################################################

    appdaemon 4.2.1 Python 3.10.6

    opened by simonepittis 1
  • The history that HomeAssistant provides is too limited

    The history that HomeAssistant provides is too limited

    I realized, after many failures and many questions, that the history of the sensors that HomeAssistant keeps is really very limited (just under 2 months) and certainly not a sufficient amount of data to make a good model.

    I think the only solution is to use a different and dedicated data source with influxDB, what do you think?

    Thankyou

    help wanted question 
    opened by dadaloop82 0
  • Data is not stored correctly

    Data is not stored correctly

    There is an error in the concept of optimizing the saving of entity states. It seems that when there is group splitting, the maximum value is not aligned with the current value or on the contrary, in any case the value is not in the expected range.

    opened by dadaloop82 0
  • api error

    api error

    api error my config file api: and I get this error Traceback (most recent call last): File "\192.168.1.58\config\appdaemon\apps\hass_predictswitch.py", line 46, in import hassapi as hass ModuleNotFoundError: No module named 'hassapi' [Finished in 281ms]

    opened by CaoHoa1 3
Owner
null
Volkswagen ID component for Home Assistant

Volkswagen ID component for Home Assistant This folder contains both a generic Python 3 library for the Volkswagen ID API and a component for Home Ass

null 55 Jan 7, 2023
Sensor of Temperature Feels Like for Home Assistant.

Please ⭐ this repo if you find it useful Sensor of Temperature Feels Like for Home Assistant Installation Install from HACS (recommended) Have HACS in

Andrey 60 Dec 25, 2022
Home Assistant custom integration for e-distribución

e-Distribución is an energy distribution company that covers most of South Spain area. If you live in this area, you probably are able to register into their website to get some information about your power demand, energy consumption, or even cycle billing (in terms of consumptions).

VMG 17 Sep 7, 2022
Home Assistant custom integration for Yi cameras: yi-hack-MStar, yi-hack-Allwinner and yi-hack-Allwinner-v2

yi-hack Home Assistant integration Overview yi-hack Home Assistant is a custom integration for Yi cameras (or Sonoff camera) with one of the following

roleo 131 Jan 3, 2023
Интеграция Home Assistant с ЛК "Интер РАО"

ЕЛК ЖКХ «Интер РАО» для Home Assistant Предоставление информации о текущем состоянии ваших аккаунтов в ЕЛК ЖКХ. Введение @ TODO @ Установка Посредство

Alexander Ryazanov 27 Nov 5, 2022
Provide Unifi device info via api to Home Assistant that will give ap sensors

Unifi AP Device info Provide Unifi device info via api to Home Assistant that will give ap sensors

null 12 Jan 7, 2023
Uses the Duke Energy Gateway to import near real time energy usage into Home Assistant

Duke Energy Gateway This is a custom integration for Home Assistant. It pulls near-real-time energy usage from Duke Energy via the Duke Energy Gateway

Michael Meli 28 Dec 23, 2022
Custom component for Home Assistant that integrates Candy/Haier Wi-Fi washing machines (also known as Simply-Fi).

Candy Home Assistant component Custom component for Home Assistant that integrates Candy/Haier Wi-Fi washing machines (also known as Simply-Fi). This

Olivér Falvai 61 Dec 29, 2022
Home Assistant integration for energy consumption data from UK SMETS (Smart) meters using the Hildebrand Glow API.

Hildebrand Glow (DCC) Integration Home Assistant integration for energy consumption data from UK SMETS (Smart) meters using the Hildebrand Glow API. T

Aniket 153 Dec 30, 2022
emhass: Energy Management for Home Assistant

emhass EMHASS: Energy Management for Home Assistant Context This module was conceived as an energy management optimization tool for residential electr

David 70 Dec 24, 2022
Python script: Enphase Envoy mqtt json for Home Assistant

A Python script that takes a real time stream from Enphase Envoy and publishes to a mqtt broker. This can then be used within Home Assistant or for other applications. The data updates at least once per second with negligible load on the Envoy.

null 29 Dec 27, 2022
Electrolux Pure i9 robot vacuum integration for Home Assistant.

Home Assistant Pure i9 This repository integrates your Electrolux Pure i9 robot vacuum with the smart home platform Home Assistant. The integration co

Niklas Ekman 15 Dec 22, 2022
Huawei Solar sensors for Home Assistant

Huawei Solar Sensors This integration splits out the various values that are fetched from your Huawei Solar inverter into separate HomeAssistant senso

Thijs Walcarius 151 Dec 31, 2022
Connect a TeslaMate instance to Home Assistant, using MQTT

TeslaBuddy Connect a TeslaMate instance to Home Assistant, using MQTT. It allows basic control of your Tesla vehicle via Home Assistant (currently, ju

null 4 May 23, 2022
Baseline model for Augmented Home Assistant

Dataset Preparation Step 1. Rename the Virtual-Home output directory to 'vh.[name]', for example: 'vh.door' Make sure the directory contains 100+ fram

Stanford HCI 1 Aug 24, 2022
Better support for Nuki devices to the Home Assistant

Another attempt to add a better support for Nuki devices to the Home Assistant Features: Lock interface implementation Uses local webhook from bridge

Konstantin 105 Jan 7, 2023
Water quality integration for Home Assistant with data provided by Budapest FVM

Water Quality FVM (Budapest, HU) custom integration for Home Assistant This custom component integrates water quality information provided by Budapest

Atticus Maximus 3 Dec 23, 2021
Automate gate/garage door opening via 433.92MHz emitter with Raspberry Pi, Home Assistant and Homekit.

Automate opening your garage door / gate Summary This project sums up how I automated opening my garage door using a Raspberry PI, a 433Mhz emitter, H

Julien Fouilhé 29 Nov 30, 2022
🏡 My Home Assistant Configs. Be sure to 🌟 my repo to follow the updates!

Home Assistant Configuration Here's my Home Assistant configuration. I have installed HA on a Lenovo ThinkCentre M93P Tiny with an Intel Dual-Core i5-

iLyas Bakouch 25 Dec 30, 2022