Hi @Kr3at0r,
The whole thing narrows down to about 5 points:
1/ Integrations
Try to always pick zwave, wifi, Cloud or some radio waves-enabled components that have HA support. This way you’ll quickly gather data points on everything you need to measure. When it’s not available right away, look, like you did here, for a python (or other) custom-made integration. MQTT is the royal alley here. Grab the data, drop them in MQTT, have HA read it, and feed a sensor or automation with it. HA is incredibly flexible and powerful so adding your own touch to it, or customizing it to the last bit is exactly what it’s created for. You’re dealing with one of the most versatile pieces of opensource I ever saw which will lead you way further than integrated hubs like samsung smarthings or the like.
2/ Integrating the Python → mqtt → HA chain
(which you seem to have done already)
If you want to check you can use one of the mosquitto binaries, which is made to listen to an mqtt channel. I find it easier than the HA version of it:
./mosquitto_sub -h localhost -p 1883 -u [YOUR USER] -P [YOUR PASS] -t '#' -v --pretty -t /# | xargs -d$'\n' -L1 bash -c 'date "+%Y-%m-%d %T.%3N $0"'
3/ Customize some of your data into your own sensors
If you have entities you wish to add, subtract or tinker with in any way, you can use custom templates. They look fairly intimidating at first, but are not so complex in the end, you can debug them in the template section of the developer tool tab. Here are a bunch, as a starting point:
- sensor:
#------------------------------------------------------------------------------------
# Wallbox
#------------------------------------------------------------------------------------
- name: wallbox_charger_wh
state: '{{ iif(states("sensor.wallbox_portal_status_description") == "Charging",
states("number.wallbox_portal_max_charging_current") | int *230,
0) }}'
unit_of_measurement: Wh
#------------------------------------------------------------------------------------
# Addition of peak and offpeak hourly consumptions
#------------------------------------------------------------------------------------
- name: hourly_energy
state: "{{ (states('sensor.hourly_offpeak_filtered') | float + states('sensor.hourly_peak_filtered') | float) | round(2) }}"
unit_of_measurement: kW
They basically allow you to create whatever new sensor, using logical operations on existing ones and store them, use them, make utility meters out of them, etc. The very same logic (Jinja templates) is available in automation, and if you ask me, this is one of the most powerful (not-so-)secret power of HA.
4/ Visualization
Many alleys here, but my go-to is Apexchart. (GitHub - RomRider/apexcharts-card: 📈 A Lovelace card to display advanced graphs and charts based on ApexChartsJS for Home Assistant)
If I recall correctly, install HACS and then Apexchart. Your goal here is to make gorgeous looking graphs. Here is an example, using my most favorite and complex chart:
type: custom:apexcharts-card
chart_type: donut
header:
show: false
title: Daily energy used
show_states: false
colorize_states: true
series:
- entity: sensor.daily_ev_charge_energy
transform: return x/1000;
name: EV cars
color: green
unit: kWh
show:
datalabels: percent
legend_value: false
- entity: sensor.daily_baloon_energy
name: Baloon
color: rgb(245, 221, 66)
transform: return x/1000;
unit: kWh
show:
datalabels: percent
legend_value: false
- entity: sensor.daily_pac_consumption
name: PAC
color: orange
unit: kWh
show:
datalabels: percent
legend_value: false
- entity: sensor.daily_heater_energy
name: Heaters
color: red
unit: kWh
show:
datalabels: percent
legend_value: false
- entity: sensor.daily_it_bay
name: IT bay
color: rgb(245, 61, 96)
unit: kWh
show:
datalabels: percent
legend_value: false
- entity: sensor.daily_office_consumption
name: Office
color: rgb(214, 60, 204)
unit: kWh
show:
datalabels: percent
legend_value: false
- entity: sensor.energy_various
name: Other
color: purple
unit: kWh
show:
datalabels: percent
legend_value: false
apex_config:
dataLabels:
enabled: true
dropShadow:
enabled: true
formatter: |
EVAL:function(value) {
return value.toFixed(0) + " %";
}
plotOptions:
pie:
customScale: 0.9
donut:
size: 35%
background: transparent
labels:
show: true
total:
show: true
label: kWh
formatter: |
EVAL:function(w) {
return Math.round(w.globals.seriesTotals.reduce((a, b) => {
return (a + b)
} , 0))
}
As usual, try, test, tinker.
This one only uses custom sensors I created from sensors declared by different integrations. Like the EV charge comes from my wallbox integration, the heaters comes from adding all the electrical consumption from my Overkiz (IO) integration, the PAC consumption comes from a Qubino zwave smart meter.
5/ Automation
Now to the big league. I started editing my automation using Visual code studio and never quite switched to the visual editor. But I tried it a couple of times and I’ve got to admit, the HA team did wonders. They could capture nearly all the power, versatility and subtlety of HA’s automation in a visual interface. Try it, love it.
Now if you want to make them by hand, here is a simple one to turn on/off a switch depending on a context, and one of the most complicated one I wrote, to only trigger alarm if a total of at least 3 security devices tilted, between my cameras and my PIRs. They can serve as simple examples to get started:
- id: "230071"
mode: single
alias: Xmas - tree off
description: Xmas tree off
trigger:
- platform: time
at: "09:30:00"
- platform: time
at: "22:30:00"
condition:
- condition: state
entity_id: "group.family_members"
state: "home"
- condition: time
weekday:
- mon
- tue
- thu
- fri
action:
- service: switch.turn_off
entity_id: switch.sonoff_10013a8b09
You can replace the trigger here by anything you’d like to tilt on, like a template that checks if your solar production is above a certain threshold for exemples. Like this one:
trigger:
platform: template
value_template: >
{% if (expand('group.doortests') | selectattr('state', 'eq', 'on') | map(attribute='name') | list | count) > 0 %}
{{ True }}
{% endif %}