MattJeanes / TeslaMateAgile

Integration to automatically fill in prices for charge data captured by TeslaMate for smart energy providers
MIT License
82 stars 10 forks source link

Help needed: "number-based entity" in HomeAssistant clarification #56

Closed goncal closed 4 months ago

goncal commented 4 months ago

Hi,

I have a sensor in HomeAssistant (entity is sensor.energy_price) that contains the price/kWh at any given moment in time. However, it does not seem to work when I configure it as

The error messages I get are:

info: TeslaMateAgile.PriceHelper[0]
      Calculating cost for charges 05/14/2024 01:00:02 UTC - 05/14/2024 04:54:03 UTC
fail: TeslaMateAgile.PriceHelper[0]
      Failed to calculate charging cost / energy for charging process 282
      System.Net.Http.HttpRequestException: An error occurred while sending the request.
       ---> System.Net.Http.HttpIOException: The response ended prematurely. (ResponseEnded)
         at System.Net.Http.HttpConnection.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
         --- End of inner exception stack trace ---
         at System.Net.Http.HttpConnection.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
         at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
         at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
         at Microsoft.Extensions.Http.Logging.LoggingHttpMessageHandler.<SendCoreAsync>g__Core|5_0(HttpRequestMessage request, Boolean useAsync, CancellationToken cancellationToken)
         at Microsoft.Extensions.Http.Logging.LoggingScopeHttpMessageHandler.<SendCoreAsync>g__Core|5_0(HttpRequestMessage request, Boolean useAsync, CancellationToken cancellationToken)
         at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
         at TeslaMateAgile.Services.HomeAssistantService.GetPriceData(DateTimeOffset from, DateTimeOffset to) in /src/TeslaMateAgile/Services/HomeAssistantService.cs:line 29
         at TeslaMateAgile.PriceHelper.CalculateChargeCost(IEnumerable`1 charges) in /src/TeslaMateAgile/Helpers/PriceHelper.cs:line 96
         at TeslaMateAgile.PriceHelper.Update() in /src/TeslaMateAgile/Helpers/PriceHelper.cs:line 74
info: TeslaMateAgile.PriceService[0]
      Waiting 1200 seconds until next update

Does the entity need to be of type "input_number"? If so, can anyone give me some indications as to how to update the value of an input_number based on the value of a sensor?

Thanks in advance!

MattJeanes commented 4 months ago

Hey, it looks like it's failing to call Home Assistant completely rather than failing to find any data

You should be able to use any numeric based entity, it does not have to be an input_number

Make sure you can call it using a tool like Postman locally to ensure you have the correct URL and authentication details

The call it makes is pretty much like this:

GET <home-assistant-url>/api/history/period/2024-05-07T04:00:00.353Z?end_time=2024-05-14T04:00:00.999Z&filter_entity_id=<your-entity-id>

With the 'Authorization' header set to 'Bearer '

You can use cURL to try it via this command:

curl --location '<home-assistant-url>/api/history/period/2024-05-07T04:00:00.353Z?end_time=2024-05-14T04%3A00%3A00.999Z&filter_entity_id=<your-entity-id>' --header 'Authorization: Bearer <your-token>'

goncal commented 4 months ago

Thanks a lot for the tip, @MattJeanes!

There was indeed a typo in the configuration (a missing "s" in "https" for the URL). Shame on me for not double-checking before opening the issue. Sorry about that! Once the typo has been fixed and cleaning up the homeassistant table (there were a few entries that contained "unavailable" instead of a float, which I need to make sure won't make it again into the system) everything has started working :)

Please feel free to close the issue and accept my apologies. Thanks again for your very useful product and for sharing it!

MattJeanes commented 4 months ago

Awesome, no problem - happy to help and see you got it working!

Top tip by the way for the unavailable problem because I had the same, you can set up an automation so that when the number sensor changes you can update an input_number with it's value. This ensures that the value is always available with it's last known value and never gets set to unavailable 🙂

stauffenberg2020 commented 3 months ago

Thanks a lot for the tip, @MattJeanes!

There was indeed a typo in the configuration (a missing "s" in "https" for the URL). Shame on me for not double-checking before opening the issue. Sorry about that! Once the typo has been fixed and cleaning up the homeassistant table (there were a few entries that contained "unavailable" instead of a float, which I need to make sure won't make it again into the system) everything has started working :)

Hi @goncal , I have hass-monta running in my homeassistant it looks like hass-monta is able to fetch the last 10 wallet transactions in some human readable YAML format.

But I am not sure how I take such a YAML like data to teslamateagile and specifically instruct that this price corresponds to that charge and so on. Do you have a tip to share?