Thank you so much for the detailed response! i am simply trying to setup my energy dashboard. i will make the new sensors and use them instead. Am i correct in thinking i still need to have the intergration installed?
Hi,
Yep, keep the enphase integration configured as we use those enphase sensors as a base to build on.
The sensors we create in post#1 use the enphase sensors as a source and we get home assistant to perform some calculations to extract the grid import and grid export figures that aren’t normally available
Hi @ned786
Just follow the first 5 posts in this thread from the beginning and you will get exactly what you wanted add be able to get the HA energy dashboard working!
Here is a nice graphical card (it mimics the Enphase app energy graph).
You need to install the custom apex charts card then add a new aspect chart to your display with this code:
type: custom:apexcharts-card
graph_span: 24h
span:
start: day
stacked: true
header:
show: true
title: Energy Map
series:
- entity: sensor.envoy_xxxxxxxxxxxx_current_energy_consumption
transform: return x *-1 ;
type: column
name: Used
color: orange
group_by:
func: avg
duration: 5min
- entity: sensor.envoy_xxxxxxxxxxxx_current_energy_production
type: column
name: Prod
color: Turquoise
group_by:
func: avg
duration: 5min
- entity: sensor.inst_energy_difference
type: column
name: Import/Export
transform: return x *-1 ;
color: grey
group_by:
func: avg
duration: 5min
Here is my “instant energy diverted sensor”, you will need to create this for the above graph to work:
# Displays the difference between Solar production and Grid import
sensor:
- platform: template
sensors:
inst_energy_difference:
friendly_name: Instant Energy Difference
icon_template: >
{% if (states("sensor.inst_energy_difference") | int(default=0) > 0) -%}
mdi:solar-panel
{%- elif (states("sensor.inst_energy_difference") | int(default=0) < 0) -%}
mdi:transmission-tower
{%- else -%}
mdi:power-off
{%- endif %}
friendly_name_template: >
{% if (states("sensor.inst_energy_difference") | int(default=0) > 0) -%}
Currently Exporting
{%- elif (states("sensor.inst_energy_difference") | int(default=0) < 0) -%}
Currently Importing
{%- else -%}
Balanced
{%- endif %}
unit_of_measurement: "W"
device_class: power
value_template: >
{{ '%0.1f' | format(states('sensor.envoy_xxxxxxxxxxxx_current_energy_production') | float(default=0) - states('sensor.envoy_xxxxxxxxxxxx_current_energy_consumption') | float(default=0)) }}
thanks @del13r , @angusc. i think i have got it all working, will find out tommorow when i have some more data. thanks again!
Hi Angus,
I like what you did with custom:apexcharts-card
I made a few tweaks to get the colors to match.
Here is Enhpase Enlighten
Here is my custom:apexcharts-card with 15 min duration
Here is my custom:apexcharts-card with 5 min duration
Here is my custom:apexcharts-card with 1 min duration
I prefer the look of 5 min duration
Note:
I only just added the net_power sensor, hence why the grey isn’t there for the whole day yet.
Here are the sensors the card uses
template:
- sensor:
name: Solar Power Corrected
state_class: measurement
icon: mdi:solar-panel
unit_of_measurement: W
device_class: power
state: >
{% set value = states('sensor.envoy_SERIALNUMBER_current_power_production') | int %}
{% if value <= 5 -%}
0
{% elif is_state('sun.sun','below_horizon') %}
0
{%- else -%}
{{ value }}
{%- endif %}
- sensor:
- name: Net Power
state_class: measurement
unit_of_measurement: W
device_class: power
icon: mdi:transmission-tower
state: >
{% set production = states('sensor.solar_power_corrected') | int %}
{% set consumption = states('sensor.envoy_SERIALNUMBER_current_power_consumption') | int %}
{{ (production - consumption) }}
Here is the updated code for the card
type: custom:apexcharts-card
graph_span: 24h
span:
start: day
stacked: true
header:
show: true
title: Total Power
series:
- entity: sensor.solar_power_corrected
type: column
name: Produced
color: '#01B4DE'
group_by:
func: avg
duration: 5min
- entity: sensor.envoy_SERIALNUMBER_current_power_consumption
transform: return x *-1 ;
type: column
name: Consumed
color: '#F37320'
group_by:
func: avg
duration: 5min
- entity: sensor.net_power
type: column
name: Imported/Exported
transform: return x *-1 ;
color: '#545456'
group_by:
func: avg
duration: 5min
Hi mate,
I can’t take any credit for the Apex-Chart, I copied it from the French HA forum . https://forum.hacf.fr/
It’s well worth checking out and I have found many useful information there, using translator within the browser.
Thanx for your updates, I used the colour coding to get a closer match to the Enphase chart.
Hi guys,
I’m trying to get my meter totals to be to 2 final places, it’s working for numbers with more than 2 decimals switch as 1.2345678 however for numbers that are totalled as 1.2 it does not make up to 2 decimals places like 1.20.
I tried applying the ceiling method but obviously not got it right:
- sensor:
name: Todays Energy Total Cost
icon: mdi:currency-gbp
device_class: monetary
state_class: measurement
unit_of_measurement: GBP
state: >
{{ (states('sensor.daily_energy_go') | float(0) * 0.05 | round(4) +
states('sensor.daily_energy_peak') | float(0) * 0.1596 | round(4) +
states('sensor.electric_tariff_standing') | float(0) -
(states('sensor.daily_energy_export_export') | float(0) * states('sensor.export_price_pounds') | float(0)) | round(2) +
states('sensor.gas_tariff_standing') | float(0) +
(states('sensor.gas_consumption_today') | float(0) * states('sensor.gas_tariff_rate')| float(0))) | round(2, "ceil") }}
Any advice or help
Thanx @del13r
Yes I have been using the developer tools and did exactly like you suggested. Rounding is ok for any number with more than 1 decimals place, then the number is rounded to 2 places. But when a single decimal place number it does not add the “0” to make it appear as a monetary number… 1.7 regains as that rather than the desired 1.70
I played a bit yesterday but couldn’t get it to parse the configuration checker
- sensor:
name: 'Todays Energy Total Cost'
icon: mdi:currency-gbp
device_class: monetary
state_class: measurement
unit_of_measurement: GBP
value_template: {{ "{:.2f}".format (states('sensor.todays_energy_net_total_cost')) | float(0) }}
I will have to keep trying, but here is my thoughts…HA
HI,
Unfortunately, it appears that there is a bigger issue at play here with using floating point numbers for currency.
see
https://stackoverflow.com/questions/34302749/why-does-float-cut-off-trailing-zeros
and
https://community.home-assistant.io/t/template-sensor-to-state-the-last-zero/330081/13
and
https://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represent-currency
and
https://docs.python.org/3/tutorial/floatingpoint.html
It seems the format() only applies to strings and does not apply to numbers.
Depends on what you want to do with the number?
If you want it to be able to be graphed, or to have this number manipulated by other sensors and used in other calculations, then a string will not work.
If you want it to just look pretty on a dashboard, then a string will work.
In order to make it a string, you pretty much just need to insert a text character to no longer make it a number. In my case I put a $ before the {{ }} section.
This is how I did it just using a static value for testing
template:
- sensor:
name: test5
state: "${{ '{:.2f}'.format(6.5) }}"
or this is the older way of doing it.
Seems to provide the same result.
sensor:
- platform: template
sensors:
test3:
value_template: "${{ '{:.2f}'.format(4.5) }}"
Notice how it no longer graphs?
Now it just shows in the history when the string value changes to a different string value in a flat time line.
This is because it is no longer a number, and is now a string and strings cannot be graphed.
Bonus: Here is another example of a string that I currently record the history of when it changes that shows the days are getting shorter.
If you choose to store currency as a string, your history graph will look a bit like this too.
LOL thanx for your further investigation, now I must ask the basic question of HA. If the sensor is set up as a “Monetary” value then surely it should be formatted to the expected 0.00 no matter what. There seems to many times that units are an issue in HA and I would love to see that aspect improved in the future. I would love to see units selectable from the Dashboard Card so that you can select a divider to make Watts in to kW or vise versa. As an end user I don’t see why it cant be that easy…but I suppose there must be a technical reason why it is not that easy.
Hi,
Yeah thats one for the Home Assistant LoveLace Devs.
After reading those links about floating point, I can sort of appreciate why they might struggle doing so.
Perhaps they should give us something else to store currency figures as other than integer or floating point numbers? Perhaps there already is another way and I’ve missed something.
This link says that monetary device class is just a way of assigning a relevant symbol.
I
I think the issue with this is granularity of data.
Say If I have a sensor that only records in kW and I pull a slider to W (which divides it by 1000), some users might expect the graph to look 1000 times more detailed however there isn’t enough granular data to fill in the gaps in the graph between 6 kW to 7kW for example. It will just show as a large jagged step on the graph.
Ugly looking jagged graph for example
I’ve now created a Home Assistant addon that outputs mqtt from the json steam http://envoy.local/stream/meter
It’s easy to install and configure via a single click of the “add Repository” button in the updated instructions:
https://github.com/vk2him/Enphase-Envoy-mqtt-json
Thats awesome! Great work!
@del13r Out of interest, have you tried @vk2him ’s new mqtt add on? I’ve been chatting to him on the repo because I’ve been having some trouble getting it to work reliably. For me, sometimes it kicks in immediately, sometimes it doesn’t, sometimes it kicks in after several minutes etc. Just looking for another data point…
Hi,
I finally got around to doing this.
The only issue I had was that I started doing it on mobile and the configuration tab was not initially obvious to me. On mobile it just shows some gears at the bottom of the page where as on desktop/laptop it actually says the word configuration on the top of the page.
Once I got past that, i was able to configure the addon with the same details I had in the original script I used to run and it now works perfectly.
One thought I had as I was configuring this addon was that in the past I used to use hostnames instead of IP addresses and I would experience issues if I rebooted my router.
I then started reading how home assistant under certain conditions might use cloudfare dns rather than the dns on your lan. see Local DNS! - #109 by CentralCommand
I then replaced my hostnames like envoy.local with the actual IP address in an attempt to give it more resiliency.
@del13r Thanks for getting back. The problem I had with long delays before the add-on kicked in seems to have been solved by a Core reboot. I’m very happy with having this run inside HA - one less thing to worry about. Thanks @vk2him! It will be interesting to see how the V7 firmware issue plays out in the long run.