EMHASS add-on: An energy management optimization add-on for Home Assistant OS and supervised

I would recommend starting with a simple optimisation rather than trying to get all your systems working at once - for example some rules to ensure your pool pump is only running off excess solar. Then as we build out your system, we could then start to include the elements of EMHASS.

My pool pump draws 1400W so we can assume the same for yours, but you can adjust the rules below.

power_load_no_var_loads = household_loads - pool_power

Turn on your switch.pool_pump when:
pv_grid - power_load_no_var_loads > 1400 W for more than 5 minutes

Turn off your switch.pool_pump when:
pv_grid - power_load_no_var_loads < 1400 W for more than 5 minutes

In EMHASS terms (assuming your fronius reports in kW - hence the *1000 below):

template:
  - sensor
    - name: power_photovoltaics
      device_class: power
      state_class: measurement
      unit_of_measurement: W
      state: "{{ states('sensor.power_ac_fronius_inverter_1_http_192_168_0_201')|float(0)*1000 }}"

    - name: power_load_no_var_loads:
      unit_of_measurement: W
      device_class: "power"
      state: >-
        {{states('sensor.power_load_fronius_power_flow_0_http_192_168_0_201')|float(0)*1000
        - states('sensor.athom_smart_plug_v2_power')|float(0)
         }}

  - binary_sensor
    - name: pool_filter_pump:
      state: >-
        {{(states('sensor.power_photovoltaics')|float(0) 
        - states('sensor.power_load_no_var_loads')|float(0))
        >= 1400  }}

Check this in your Developer Tools tab to make sure the values are correct:

If that is good then copy into your configuration.yaml file, reload template variables and ensure those sensors are now functional.

Once you are happy with these variables, then you can create an automation, in the create empty automation with the following elements:

Finally setup a nice dashboard.

1 Like

Thanks, I will have a crack.

Yeah, mine only draws ~320 W during main duty cycle. One of the benefits of an efficient multispeed pump. My old single speed pump used to draw ~1200 W and was an energy hog. The pump does have a 5-min start up cycle which draws at a bit over 900 W but once done it drops back to all day running speed. Throughput is ample for cycling the water in the 50,000 litre pool.

At present it operates on a variable duration duty cycle based on offsets to sunrise and sunset, which means the duration of the duty cycle varies with the seasons. Works well.

Being only 320 W then itā€™s pretty rare for there to not be enough solar PV capacity from the 11 kW grid PV system but itā€™s the principles Iā€™m trying to learn with EMHASS, so itā€™s a good start.

So I guess the optimisation could decide when to commence and finish operating within the start/finish times defined by the sunrise/sunset offsets, or some other parameter which can vary the length of the duty cycle based on seasonal variances. I donā€™t really want it to turn off and back on during the day, one duty cycle is preferred.

I think it reports in W not kW but Iā€™ll check and make the adjustment as needed.

1 Like

OK, I made a couple of minor adjustments and have this in the developer template:

template:
  - sensor
    - name: power_photovoltaics
      device_class: power
      state_class: measurement
      unit_of_measurement: W
      state: "{{ states('sensor.power_ac_fronius_inverter_1_http_192_168_0_201')|float(0) }}"

    - name: power_load_no_var_loads:
      unit_of_measurement: W
      device_class: "power"
      state: >-
        {{states('sensor.power_load_fronius_power_flow_0_http_192_168_0_201')|float(0) * -1
        - states('sensor.athom_smart_plug_v2_power')|float(0)
         }}

  - binary_sensor
    - name: pool_filter_pump:
      state: >-
        {{(states('sensor.power_photovoltaics')|float(0) 
        - states('sensor.power_load_no_var_loads')|float(0))
        >= 900  }}

I removed the divide by 1000 as the Fronius sensors report in watts, not kW.

I also multiplied the sensor.power_load_fronius_power_flow_0_http_192_168_0_201 by -1 as it reports loads as a negative value.

And I changed the pool pump threshold to 900 W to align with my pumpā€™s start up power draw.

This is sample output:

Good news is there are no errors showing in the template, so thatā€™s a win!

But Iā€™m not sure why itā€™s reporting ā€œfalseā€ for the pool_filter_pump binary_sensor given PV production well exceeds loads, certainly by more than 900 W.

Great work.

Yaml is designed for strings, but we are doing math which is why the command get so long, but you seem to have the hang of it.

The reason why it is coming back as false is you havenā€™t yet setup those sensors in HA, so they are coming back as zero for now.

Next step is to copy those lines into your configuration.yaml file. I recommend the Studio Code Server addon-vscode/vscode/DOCS.md at 9d6f6aa2307f69d92718d3611da26d5277c128a1 Ā· hassio-addons/addon-vscode Ā· GitHub

Then Check and Restart from Developer Tools.

1 Like

Thanks.

Iā€™m having some trouble with the binary sensor. The editor doesnā€™t like it.

The other sensors were showing many errors. I had to muck about with various things to get those to work, adding/deleting spaces, changing dashes, removing quote marks and so on. Iā€™ve zero idea what I am doing though, just trying things without knowing what the code is supposed to look like.

Bit concerned my yaml configuration file is now broken.

think I found it,
- binary_sensor needed a colon placed after it
- binary_sensor:

1 Like

OK, progress. I can confirm the sensors all appear in the Developer tools States tab.

1 Like

Great, I would put those sensors on a history card on one of your dashboard to track how they are going.

Either track that for a day or so or build the automation to switch your pump on and off.

Does this look correct or an I doing something wrong.

OK, have put this dashboard together:

Iā€™ve set the history cards to show last 24 hours but of course all the new entities will need a full day to populate that far back.

The top sensor ā€œPool pumpā€ shows the automation I current have running (with start/stop based on offsets to sunrise/sunset).

The Pool pump binary sensor is using the 900 W threshold, which is really only relevant for the 5-minute long start up cycle.

So we can see how that tracks, at least for tracking the start time when the power draw will be 900 W.

I guess I have two binary sensors, one for when to turn the pump on, and one for when to turn the pump off given the start up power demand is higher than the regular running power demand.

I am really enjoying this thread at the moment. Some good newbie questions (which is about my level) and some really considered and easily understandable answers.
This gives me confidence to have a bit more of an exploration of templates.
Thanks
Pat

1 Like

Youā€™re not using the correct URL

The add-on repository and installation instructions are here: https://github.com/davidusb-geek/emhass-add-on

1 Like

I adjusted the sensor history card to show all three sensors on one card. This at least time aligns them.

The card will better show the difference between when then new pool_filer_pump sensor says there is enough power to start the pump vs when it actually starts with its existing automation.

Sunny this morning so I expect it will say I can start the pump much earlier than I actually do. But storms expected later this morning.

Iā€™m really appreciating the help.

1 Like

OK, since adding the pool pump entity into the system, Iā€™m at a loss at to what I do next.

In the documentation it says:

You must follow these steps to make EMHASS work properly:

  1. Define all the parameters in the configuration file according to your installation. See the description for each parameter in the configuration section.
  2. You most notably will need to define the main data entering EMHASS. This will be the sensor_power_photovoltaics for the name of the your hass variable containing the PV produced power and the variable sensor_power_load_no_var_loads for the load power of your household excluding the power of the deferrable loads that you want to optimize.
  3. Launch the actual optimization and check the results. This can be done manually using the buttons in the web ui orwithacurlcommandlikethis:curl -i -H ā€˜Content-Type:application/jsonā€™ -X POST -d ā€˜{}ā€™ http://localhost:5000/action/dayahead-optim.

Step 1. we did some of it previously but much of the config file I still donā€™t follow what I am supposed to enter. Yes I have read the documentation. Further questions below.

Step 2. we did last time.

Step 3. I tried clicking on the buttons in the web UI but nothing happens.
.

I have some questions about the configuration file.

hass_url: empty
long_lived_token: empty

Do I leave these as empty?
.

costfun: profit

Iā€™m not sure which to use.
.

optimization_time_step: 30
historic_days_to_retrieve: 2
method_ts_round: nearest
lp_solver: COIN_CMD
lp_solver_path: /usr/bin/cbc

I guess i just leave these alone?
.

set_total_pv_sell: false

What is this?
.

number_of_deferrable_loads: 2
list_nominal_power_of_deferrable_loads:
  - nominal_power_of_deferrable_loads: 3000
  - nominal_power_of_deferrable_loads: 750
list_operating_hours_of_each_deferrable_load:
  - operating_hours_of_each_deferrable_load: 5
  - operating_hours_of_each_deferrable_load: 8

Not sure what to enter here. For instance most loads I would call deferrable (such as washing machines, clothes dryers, dishwashers etc) are variable power loads, not something with a fixed power draw. Their duration of operation also varies.
.

list_peak_hours_periods_start_hours:
  - peak_hours_periods_start_hours: "02:54"
  - peak_hours_periods_start_hours: "17:24"
list_peak_hours_periods_end_hours:
  - peak_hours_periods_end_hours: "15:24"
  - peak_hours_periods_end_hours: "20:24"
list_treat_deferrable_load_as_semi_cont:
  - treat_deferrable_load_as_semi_cont: true
  - treat_deferrable_load_as_semi_cont: true
load_peak_hours_cost: 0.31
load_offpeak_hours_cost: 0.18
photovoltaic_production_sell_price: 0.076

Not sure how to enter in peak hours. We have 3 different TOU tariffs (well 4 really) and when they occur depends on the day of the week.
.

maximum_power_from_grid: 12000
With a 3-phase supply I guess itā€™s in the vicinity of 23 kW. Not that I have ever drawn that much or ever plan to.
.

list_pv_module_model:
  - pv_module_model: Trina_Solar_TSM_275DEG5_II_
list_pv_inverter_model:
  - pv_inverter_model: Fronius_International_GmbH__Fronius_Symo_10_0_3_208_240__240V_
list_surface_tilt:
  - surface_tilt: 23
list_surface_azimuth:
  - surface_azimuth: 22
list_modules_per_string:
  - modules_per_string: 10
list_strings_per_inverter:
  - strings_per_inverter: 4

Not sure how to complete this section. Panel model is a guess.
I have two PV inverters, one grid-tied, one off-grid. There are arrays covering three different orientations. How do I deal with different orientations, and with two inverters?
.

set_use_battery: true
battery_discharge_power_max: 4000
battery_charge_power_max: 2500
battery_discharge_efficiency: 0.95
battery_charge_efficiency: 0.95
battery_nominal_energy_capacity: 10000
battery_minimum_state_of_charge: 0.1
battery_maximum_state_of_charge: 1
battery_target_state_of_charge: 0.6

My battery is off-grid. Not sure if that matters?
.

What else am I missing? The configuration documentation seems to refer to many things which donā€™t appear in the HA configuration page.

Your post is a blow to the time I spent writing a documentation that I thought was clear and complete enough.

Not sure what to make of that.

Itā€™s just the reality of my experience. If I donā€™t follow what is written or canā€™t find an answer, should I not ask for clarification/guidance?

ĀÆ_(惄)_/ĀÆ

There is no obligation on you or anyone to answer such questions or assist. It just means without it Iā€™m unlikely to progress beyond where I am.
.

Let me give one example of what is written quite clearly versus what it is about it I donā€™t understand. This from the configuration file documentation:

Now please understand, I donā€™t know what the phrase Home Assistant instance means and the example given doesnā€™t shed any light for me either.

So I go look it up and find my way to this link which talks about connecting to a Home Assistance instance, hoping it might enlighten me:

but Iā€™m still none the wiser. Further Googling of the term reveals little.

So I search for the example given https://myhass.duckdns.org/ but thatā€™s not helpful either in working out what it is I am looking for.

In my HA, under
Settings / System / Network
there is a card titled Home Assistant URL which gives a local URL:
https://homeassistant.local:8123

but thatā€™s not an external IP address like in the example given.

Hence I ask for guidance.
.

Like I said, if I am helped to understand, thatā€™s great and I will be grateful but I completely understand if not since it is time consuming.

Hi,

I have just recently come across this addon as I am starting to look at optimising power usage in my house. While I am still working through the configuration, I think I have it sorted in my head for how to handle ā€˜simpleā€™ deferable loads such as the dishwasher or washing machine, that would generally run once per day.

What I am less clear on is loads that I would consider more complex. For example, if I have a pump that needs to run for 20 mins every 2 hours, but can run anytime in that 2 hour window. i.e. it is recurring but has some flexability in scheduling. Or the other use case is my house AC. I want to run it off excess solar generation, but it can afford to have a delayed start up to a certain point because it is a long running load. ie it could turn on as late as lunch time allowing other smaller loads to go first.

I have been reading through the doco trying to understand if there is support for such senarioā€™s. Is the optimiser capable of such logic?

I think that maybe you are diving in at a fairly complex level. I think it is best that these guys time is left to develop the core complex system and i may be able to give you a hand via PM so as not to clog up the info in this stream . ā€¦ .

@RatMondeo , the guide for posting says that PMs are greatly discouraged, as then everyone does not benefit from the knowledge shared. This is a great thread, and I am learning quite a bit from it, so please letā€™s keep this topic out in the open.

Having some trouble to get accurate pv forcast in the emhass.

list_pv_module_model:
  - pv_module_model: CSUN_Eurasia_Energy_Systems_Industry_and_Trade_CSUN295_60M
list_pv_inverter_model:
  - pv_inverter_model: Fronius_International_GmbH__Fronius_Primo_5_0_1_208_240__240V_
  - pv_inverter_model: Fronius_International_GmbH__Fronius_Primo_5_0_1_208_240__240V_
list_surface_tilt:
  - surface_tilt: 25
list_surface_azimuth:
  - surface_azimuth: 135
list_modules_per_string:
  - modules_per_string: 12
list_strings_per_inverter:
  - strings_per_inverter: 1

Have no idea if this is configured correctly.

Panels are: Axitec AC-360MH/120V
Inverters are: SUN-5K-SG03LP1-EU

I have 2 inverters and 24 panels. 12 panels on each inverter in a single string.