Add sensor to ouput Import and Export in Watts or kWh #9
Replies: 14 comments 22 replies
-
Hi @Roving-Ronin - thank you for your feedback. Integration with the HA Energy module should not be difficult and the SA integration already provides everything you need. Importantly, don't mix up your power draw in units Watts or kilo-Watts, with your energy usage which is in units of Watt-hours or kilo-Watt-hours - which also the units that you pay for in $/kWh. I trust that you're using the latest "solar_analytics.yaml" file as published in August. As described in the code header comments ... to complete the HA Energy Configuration, enter the details for
For example, here is my config for Grid consumption: The sensors above are in Wh and the Energy module does any conversions (e.g. to kWh) as required. My energy data as displayed by the HA Energy module as good as matches the data in the Solar Analytics portal (subject to any minor timing discrepancies). I hope this helps. If not, let me know and we can organise a time to chat further. |
Beta Was this translation helpful? Give feedback.
-
Hi Peter,Thanks but I wasn’t referring to the data sources for using to track the kWh being used / exported, but said data (in W or kWh instead of Wh) so it can be used to define an entity that tracks and calculates the actual running daily cost in the energy dashboard.Ie below where you’ve chosen your Total Daily Export / Import, and then have four options to add in / track the cost of it.
As per this screenshot:
![GitHub-HA](https://user-images.githubusercontent.com/108674933/209897927-03efb3c5-49f4-4937-88da-4c3353a4a628.jpg)
|
Beta Was this translation helpful? Give feedback.
-
Hi @Roving-Ronin - I'm with Amber so use their HA API integration for realtime price updates (changes every 5 mins or so). My EM daily cost total is usually within about 30c compared to that calculated by Amber (likely a meter read/time-sync issue). See image below. What's your source for your retailer's unit-rate ($/kWh) data? Is it fixed (ie. "use a static price"), or do you have peak/off-peak/shoulder time of day unit-rates? If the latter, then you need to create an "entity with the current price" which driven by the time-of-day could be created as an automation or in Node-Red. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
I should add that I do nonetheless have sensors in kWh and kW that are used for display purposes. Rather than code in YAML, I've simply implemented the conversions in Node Red. |
Beta Was this translation helpful? Give feedback.
-
Hi @Roving-Ronin - HNY!!! The conversions do otherwise create a near duplicate data set in the HA database. I would like to think there's a smarter way so the data is only converted and rounded when required. Nonetheless, here's the additional code I'm trialling (tagged onto the existing). As a bonus, it includes a new SA API get of expected Wh solar generation (days total to the current hour - matching the data found on the SA portal's Production tab - the grey graph bar). You will note some comments regarding the timestamp setting - maybe it should be "now" rounded down to the last hour - e.g. 2023-01-03 09:55:38 becomes 2023-01-03 09:00:00. Thoughts? Let me know how you go.
|
Beta Was this translation helpful? Give feedback.
-
Hi Peter, I keep on noticing that whilst sensor.sa_energy_generated_expected_data is receiving updates, that sa_todays_energy_generated_expected_total (and the kWh conversion) are constantly showing errors as status = Unavailable. |
Beta Was this translation helpful? Give feedback.
-
Hi @Roving-Ronin I'm away at the moment so will only respond in brief until the weekend. The SA public app can be found via the following link. I have found it to be somewhat limited and ended up deciphering the rest get calls as used on their website. As such some of the gets I use are not official nor supported. This includes the get for the expected generation. I am not sure why it might be failing sometimes. |
Beta Was this translation helpful? Give feedback.
-
Hi Peter, Pending testing it does what is promises, it appears this need to convert from Wh to kWh has been removed with the release of 2023.2 that mentions "Got an energy sensor in Wh, but you’d like it to be kWh? You can now change the units of energy sensors in the entity settings." |
Beta Was this translation helpful? Give feedback.
-
Wondering where you see the "state class of this entity is not supported" error/issue? I've simply set it up the same as the "Total Energy Generated" sensor which is what the expected sensor is trying to predict to the current hour. Both of them accumulate throughout the day (not go up/down) and then reset at midnight. If I change the latter to 'total', then I should also change the others which nonetheless seem to work okay with HA EM. See the image example of the two in my HA set-up below. Does yours look the same? |
Beta Was this translation helpful? Give feedback.
-
Hi @Roving-Ronin - so today the results purely from a sensor "total" perspective look the same as "total_increasing". However, the HA EM interprets the total differently and doesn't see the midnight reset to zero as a start of a new meter cycle, rather a negative energy usage. As such our Stove Oven Energy yesterday at midnight reached 0.21kWh for the day, and today to the moment it has reached 0.20kWh with EM reporting -0.1kWh as a relative net decrease - and not 0.20kWh as expected. https://developers.home-assistant.io/docs/core/entity/sensor/#available-state-classes This behaviour does seem to be as described by the "Sensor Entity" state_class definition. While "total_increasing" does generate a warning, it does seem to work okay compared to "total" and as such I'm inclined to leave the code as is above. See image. Thoughts? |
Beta Was this translation helpful? Give feedback.
-
"sa_todays_energy_generated_expected_total" (expected) and its peer "sa_todays_energy_generated_expected_total" (actual) are both hour-by-hour cumulative generated energy in kWh that reset at midnight. The two are shown together in the chart on the SA Production page (https://my.solaranalytics.com/au/production/). I feel if one is total_increasing then so should the other. As a sensor only, I would expect "sa_todays_energy_generated_expected_total" to work as either a total or total_increasing. However, things like the HA EM clearly don't understand total for other sensors such as my SA stove-oven, hot-water, heating-cooling and EV-charging kWh. As such I think for consistency it's best left as is despite the warnings (which maybe need review on the HA side?). "sa_todays_energy_exported_compensation" and "sensor.sa_todays_energy_imported_cost" are news to me and the sensors must come from the EM; they appear to match the imported and exported energy costs as shown below. Never used them, but useful to know about and I'll add them to the documentation for the SA integration. Both appear to be hidden entities. Looks like the revised code above stands as-is for the time being. |
Beta Was this translation helpful? Give feedback.
-
Hi Peter, Seperate issue, but just realised the sensors that I have for pulling gas m3 (via a reed switch using pulse_meter), with recent HA updates are now timing out when restarting HA, leading to them default to zero then reading the existing reading when it becomes available and adding that to whats already stored.. end result restart HA and the "Gas Meter Reading - m3" readings all double. Here's the sensors I have, that read an ESP32 with the reed switch, being 'sensor.gas_meter_reading'. These sensors then apply the gas retailers 'correction factor' to come up with their 'corrected m3' reading and that is then mulitplied by 38.29 to convert from m3 to MJ. Based upon sensor in ESP device being configured as type PULSE meter.
Takes sensor called 'gas_meter_reading' from the ESPHome device. Based upon the meter recording in 0.01m³ increments (10L)
Takes the above sensor 'gas_meter_reading_m3' and applied the 'heating value' as determined by the retailer, to convert from m3 to MJ.
Any assistance / advice appreciated. |
Beta Was this translation helpful? Give feedback.
-
Hi @Roving-Ronin |
Beta Was this translation helpful? Give feedback.
-
Hi,
Thanks for this great integration ! I've been using it for a while now and just looked to add the ability to calculate power costs in the Energy Dashboard. Unfortunately it appears that HA, when defining an entity to track power total costs for the day, works on the basis that data being feed in, is either Watts or kWh. Given that SA / this integration outputs the import/export in Watt Hours (Wh) its proving a real pain to get it working.
Just wondering if there's any chance you might be able to add an extra lot of sensors to output the sa_todays_energy_imported and sa_todays_energy_exported with a corresponding alias in kW (i.e. sa_todays_energy_imported_kw and sa_todays_energy_exported_kw), or even plain Watts (users could then just add a Riemann sum integral (left), that would allow converting W to kWh easily.
Going from Wh, given its watts x , but how long is that period of time to divide it by to get back to W, is the painful issue.
Thanks !
Beta Was this translation helpful? Give feedback.
All reactions