Energy Management in Home Assistant

Yes I can … question is: How?

I have a virtual machine running on Hyper-V, so what do you need?

in node red, top right, click on the hamburger.
select export and then current flow. click on copy to clipboard bottom right.
open notepad,
paste contents of clipboard, save… :slight_smile:

G

I know that yes … what about the rest you asked for? Or is it only NodeRed?

hehehe oh now realised … more words George.

just after the node red flow please. like you flow… can customise the various thresholds for mine and use the same intelligent management.

really have to get a 3rd battery some time. eish budget…

G

Exported to Clipboard … can you use this … otherwise PM me your email address.

[{"id":"cfced24c.fcba2","type":"tab","label":"Optimal Panel Usage","disabled":false,"info":""},{"id":"62df7244.01089c","type":"modbus-read","z":"cfced24c.fcba2","name":"Grid Status","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"100","dataType":"InputRegister","adr":"826","quantity":"1","rate":"30","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"c4ac03f9.3d1d5","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":110,"y":80,"wires":[["aa368acb.cb6be8"],[]]},{"id":"aa368acb.cb6be8","type":"debug","z":"cfced24c.fcba2","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":330,"y":80,"wires":[]},{"id":"b8a651ac.92cba","type":"modbus-read","z":"cfced24c.fcba2","name":"250/100 Watts","topic":"Solar_Generation","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"100","dataType":"InputRegister","adr":"850","quantity":"1","rate":"30","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"c4ac03f9.3d1d5","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":120,"y":160,"wires":[["d6a96d70.c63f9","18ba4adc.e46b65"],[]]},{"id":"d6a96d70.c63f9","type":"debug","z":"cfced24c.fcba2","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":330,"y":160,"wires":[]},{"id":"4ea64ac4.4ff394","type":"modbus-read","z":"cfced24c.fcba2","name":"Batt Watt","topic":"Battery_Watts","showStatusActivities":false,"logIOActivities":false,"showErrors":true,"unitid":"100","dataType":"InputRegister","adr":"842","quantity":"1","rate":"30","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"c4ac03f9.3d1d5","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":100,"y":320,"wires":[["18ba4adc.e46b65","87c3ad12.84ae5"],[]]},{"id":"58357a35.9ceb64","type":"debug","z":"cfced24c.fcba2","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":330,"y":240,"wires":[]},{"id":"18ba4adc.e46b65","type":"function","z":"cfced24c.fcba2","name":"","func":"minESS = 500\t\t// ESS Inverter Setting\nMaxBattDC = -200\t// As batt meer as die waarde ontlaai, Verlaag ESS - was 100\nMaxBattCH = 200\t\t// As batt laai teen die waarde, dan word ESS opgestoot. - was 100\nFactor = 0.2\t\t// Factor by with the ESS vaule is set - this is to ensure that the pannels match the dischrge\n\nswitch (msg.topic)\n{\n    case \"Solar_Generation\":\n        Solar_Generation = msg.payload[0]*1\n        context.Solar_Generation = Solar_Generation\n        if (Solar_Generation <= minESS)\n            {\n                newMax = minESS\n                context.essetting = newMax/10\n\t\t    } \n\t\telse\n\t\t\t{\n\t\t\t\tnewMax = (Math.ceil(Solar_Generation / 10) * 10);\n\t\t\t\tcontext.essetting = newMax/10\n\t\t\t\tnode.status({shape:\"ring\",text:\n\t\t\t\t                \"Batt:\" + Battery_Watts \n\t\t\t\t                + \"w ESS Watts:\" + context.ESS_Watts * 10\n\t\t\t\t                + \"w Solar:\" + context.Solar_Generation\n\t\t\t\t                + \"w New Max:\" + context.essetting * 10\n\t\t\t\t    \t\t});\n\t\t\t}\n        break\n        \n    case \"ESS_Watts\":\n        context.ESS_Watts = msg.payload[0]*1\n        break\n        \n    case \"Battery_Watts\":\n        Watts = msg.payload[0]*1\n        \n        if ( Watts > 10000)\n            {\n                Battery_Watts =Watts - 65535\n            }\n        else if (Watts == 0)\n            {\n               Battery_Watts = 110\n            }\n        else\n            {\n             Battery_Watts = Watts\n            }\n        \n        node.status ({shape:\"ring\",text:\n                        \"Batt:\" + Battery_Watts\n                        + \"w ESS Max:\" + context.ESS_Watts * 10\n                        + \"w Solar:\" + context.Solar_Generation\n                        + \"w New Max:\" + context.essetting * 10\n                    });\n      \n        if (Battery_Watts <= MaxBattDC && context.ESS_Watts >= minESS || context.minESS < minESS )\n            // Battery is Discharging and ESS is still to high\n            {\n                msg.payload = (context.essetting*1).toFixed(0)\n                return msg;\n            }\n        else\n            // Solar is enough to sustain the curr house load load\n            if (Battery_Watts >= MaxBattCH )\n            {\n                msg.payload = (context.essetting*1).toFixed(0)\n                return msg;\n            }\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":320,"wires":[["d7b6b9e8.06aa98","c9935bee.dd5008"]]},{"id":"dccc8d78.f5ee5","type":"modbus-read","z":"cfced24c.fcba2","name":"ESS Max","topic":"ESS_Watts","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"100","dataType":"InputRegister","adr":"2704","quantity":"1","rate":"30","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"c4ac03f9.3d1d5","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":100,"y":240,"wires":[["58357a35.9ceb64","18ba4adc.e46b65"],[]]},{"id":"d7b6b9e8.06aa98","type":"debug","z":"cfced24c.fcba2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":260,"wires":[]},{"id":"87c3ad12.84ae5","type":"debug","z":"cfced24c.fcba2","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":330,"y":320,"wires":[]},{"id":"c9935bee.dd5008","type":"modbus-write","z":"cfced24c.fcba2","name":"Write ESS","showStatusActivities":false,"showErrors":true,"unitid":"100","dataType":"HoldingRegister","adr":"2704","quantity":"1","server":"c4ac03f9.3d1d5","emptyMsgOnFail":true,"keepMsgProperties":false,"x":710,"y":300,"wires":[[],[]]},{"id":"c4ac03f9.3d1d5","type":"modbus-client","name":"Cerbo","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"192.168.0.50","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"100","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true}]
1 Like

will import it a bit later and unpack and get back to you.

G

hi hi, imputed. got the modus units to pull the values, for now disables the push out, first want to understand the values.
call tomorrow.
G

I like what they’re doing with the Home Assistant “Amber”:

Home Assistant Amber | Crowd Supply

2 Likes

I did not get myself the Blue, but I’m actually keen on getting one of these.

I"ll do the compute module with the Wifi onboard,

love how they got themselves around the regulatory standards, if they included multiple wifi standards on board then they would have major certification problems, but leaving this for the buy to do via the CM04, clever. and then also the M.2, so you do’t sit with a SD card that dies because of to much IO activity.

G

Gents,

I got my energy dashboard going with Victron modes and Fronius Integrations for Solar inputs. I also have my grid in and out via Shelly.

I would like to now add my battery to see the charge and discharge kWh as well. I do see this in HA:

  • name: “Battery Power System”
    unit_of_measurement: “W”
    slave: 100
    address: 841
    data_type: int16
    scale: 1.0
    precision: 2
    device_class: power
    #device_class: energy
    state_class: total_increasing
    • name: “Charge Power System”
      unit_of_measurement: “W”
      slave: 100
      address: 842
      data_type: int16
      scale: 1.0
      precision: 2
      device_class: power
      #device_class: energy
      state_class: total_increasing

How do I get the W converted to kWh and get the energy dashboard to see this please? Any help appreciated
Groetnis

And those registers were wrong anyhow:

There appear to be so many conflicting solutions in the forums. I’ve been struggling with it myself. I will put more time into it during the holidays.

Also running RPI4 with 4GB on USB3 SATA SSD - works well and stable.
Using RaspberryOS 10 Lite (Debian 10) with Docker - waiting for RaspberryOS 11 64bit for next upgrade.
The RPI4 is OC’ed to 2Ghz with containers for:
Home-Assistant, MQTT, PostgreSQL, Samba NAS, Pi-Hole DNS & DHCP, WireGuard, Grafana, and a few others.
RPI4 is also my internet router PPPoE to ISP - I use a VLAN switch to segregate the traffic.
RPI4 also manages Fibre to LTE fail over/fail back when fibre goes down.
I use nftables firewall to block unwanted traffic.
CPU load is about 5% with plenty of free RAM and handles 1GbE routing fine (tested with iperf3 between WAN eth0.16 and LAN eth0.1 ports).

Impressed with Docker and amazed how much a little RPI4 can do.
With Docker, it’s really easy to upgrade or rebuild a container.
Upgraded HA to 2012.12 was a 1 minute task.|

I’ve have the energy integration working for about 10 days:

image

Nice, prezacetly what I would like, see them storage device energy. I take it the hubble is a Can bus device?

My difficulty is that Can bus devices are not supported as energy (kWh) in the energy dashboard, just power (kW) so cannot be directly used. The conversion needs to happen to kWh and then the energy class needs to be defined.

What registers are you using to get the battery data in there? Also can you please share the code and if you used templates etc? The guidance would be appreciated.

Groetnis

I’m using Solar-Assistant on an old RPI3 that then feeds HA on my RPI4 container.
The latest update of Solar-Assistant provides power (kW) and energy (kWh) and fixed the HA energy integration.
Prior to the update, I used a small python app to convert the real time kW readings averaged over the last minute to kWh.
Typically SA provides about 100 samples per minute - I take the average of the 100 samples over the minute and computer the kWh.

This is from my Modbus file:
- name: “Battery Power System”
unit_of_measurement: “W”
slave: 100
address: 842
data_type: int16
scale: 1.0
precision: 2
device_class: power
scan_interval: 10

And the data:

So it seems we need to convert from Watts to kWH (reading every 10 seconds) and then get the negative (discharge) to reflect the battery out and the positive as battery in energy.

Groetnis

@system32 Would you please share the config and code of how you got this to show up? Is this on Can- bus?

Groetnis

Solar-Assistant is connected to SunSynk RS485 port and the Hubble RS232 console port.
Solar-Assistant does the clever modbus/canbus connections/protocol and publishes power (W), Volts, Amps, Temperature, SoC, etc to MQTT
Solar-Assistant was missing energy (kWh).
The 2021-12 update of Solar-Assistant added energy (Wh) to MQTT and made my script redundant.

I wrote a python3 script that listens on MQTT and persists the data to PostgreSQL.
The python3 script averages the MQTT power (W) values over a 1 minute period to compute energy (Wh).
If you have Solar-Assistant, then the script is no longer required.
If you don’t have Solar-Assistant, the script won’t help either.

I’ll cleanup the code and put it on github.

Solar-Assistant state topics:

solar_assistant/inverter_1/ac_output_voltage/state
solar_assistant/inverter_1/battery_current/state
solar_assistant/inverter_1/battery_voltage/state
solar_assistant/inverter_1/grid_frequency/state
solar_assistant/inverter_1/grid_power/state
solar_assistant/inverter_1/grid_voltage/state
solar_assistant/inverter_1/load_power/state
solar_assistant/inverter_1/load_power_auxiliary/state
solar_assistant/inverter_1/load_power_essential/state
solar_assistant/inverter_1/load_power_non-essential/state
solar_assistant/inverter_1/pv_current_1/state
solar_assistant/inverter_1/pv_current_2/state
solar_assistant/inverter_1/pv_current_3/state
solar_assistant/inverter_1/pv_power/state
solar_assistant/inverter_1/pv_power_1/state
solar_assistant/inverter_1/pv_power_2/state
solar_assistant/inverter_1/pv_power_3/state
solar_assistant/inverter_1/pv_voltage_1/state
solar_assistant/inverter_1/pv_voltage_2/state
solar_assistant/inverter_1/pv_voltage_3/state
solar_assistant/inverter_1/temperature/state
solar_assistant/total/battery_power/state 
solar_assistant/total/battery_state_of_charge/state
solar_assistant/total/battery_temperature/state

# new in 2012-12
solar_assistant/total/battery_energy_in/state
solar_assistant/total/battery_energy_out/state
solar_assistant/total/grid_energy_in/state
solar_assistant/total/grid_energy_out/state
solar_assistant/total/load_energy/state
solar_assistant/total/pv_energy/state

# Home-Assistant auto-config - new in 2021-12
homeassistant/sensor/inverter_1_ac_output_voltage/config
homeassistant/sensor/inverter_1_battery_current/config
homeassistant/sensor/inverter_1_battery_voltage/config
homeassistant/sensor/inverter_1_grid_frequency/config
homeassistant/sensor/inverter_1_grid_power/config
homeassistant/sensor/inverter_1_grid_voltage/config
homeassistant/sensor/inverter_1_load_power/config
homeassistant/sensor/inverter_1_load_power_auxiliary/config
homeassistant/sensor/inverter_1_load_power_essential/config
homeassistant/sensor/inverter_1_load_power_non-essential/config
homeassistant/sensor/inverter_1_pv_current_1/config
homeassistant/sensor/inverter_1_pv_current_2/config
homeassistant/sensor/inverter_1_pv_current_3/config
homeassistant/sensor/inverter_1_pv_power/config
homeassistant/sensor/inverter_1_pv_power_1/config
homeassistant/sensor/inverter_1_pv_power_2/config
homeassistant/sensor/inverter_1_pv_power_3/config
homeassistant/sensor/inverter_1_pv_voltage_1/config
homeassistant/sensor/inverter_1_pv_voltage_2/config
homeassistant/sensor/inverter_1_pv_voltage_3/config
homeassistant/sensor/inverter_1_temperature/config
homeassistant/sensor/total_battery_energy_in/config
homeassistant/sensor/total_battery_energy_out/config
homeassistant/sensor/total_battery_power/config
homeassistant/sensor/total_battery_state_of_charge/config
homeassistant/sensor/total_battery_temperature/config
homeassistant/sensor/total_grid_energy_in/config
homeassistant/sensor/total_grid_energy_out/config
homeassistant/sensor/total_load_energy/config
homeassistant/sensor/total_pv_energy/config

Set up a integration integration (lol) to get kWh can also do utilty meters from that point. To split the + - of the battery you can also do template sensor to split <> 0

I am trying to integrate a Pylontech batteries for two days now and I am just not getting it right :frowning:
I have spent quite a few hours and still feeling hopeless :frowning:

I am using Victron modbus and I managed to get the grid as well as pv integrated, but batteries are simply not working.
I tried the split sensor and many other things I found online to no avail.

Please can anyone that has this integrated share the template and/or yaml?