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) }}
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:
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
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
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.
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.
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.
@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…
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.
It looks like it may be safer staying with V5 for the time being.
I have seen posts suggesting contacting Enphase with downgrade request or preventing the upgrade to V7 for particular system.
Have anyone successfully tried that (contacting Enphase)?
Is the upgrade path known? Can I perhaps filter some ports / URL on my router to prevent upgrade while still keeping the cloud connectivity (until I may be able to cut the cord one day)?
Yes I contacted Enphase support by phone - after discussion the helpful lady I spoke to said they could downgrade me from V7 to V5 and keep me permanently on V% till I called and asked to be upgraded. I needed v5 so my mqtt script worked. I’ve now made my script an add-on to Home Assistant to give readings once per second for realtime display
Thanks! I Just did the same. Very helpful lady (on a noisy call center line). Few minutes on hold while she talked to a senior tech support person and then confirmed I will not be upgraded unless I request to.
Time to invest into more automation! Thanks a lot for your contribution.