home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
69.75k stars 28.91k forks source link

Netatmo - Energy Control app #106507

Open dspe opened 6 months ago

dspe commented 6 months ago

The problem

Hi team,

I would like to retrieve information collected by my Legrand 412032 ( https://www.legrand.fr/pro/catalogue/ecocompteur-modulaire-connecte-pour-mesure-consommation-sur-5-postes-230v-5060hz-5-modules )

The integration detects correctly different energy lines defined on my Legrand, but all the data is set to 0

What version of Home Assistant Core has the issue?

core-2023.12.4

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS Netatmo Type: NLE (Ecometer)

Integration causing the issue

netatmo

Link to integration documentation on our website

https://www.home-assistant.io/integrations/netatmo/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

tmenguy commented 1 week ago

The webhook part is not an issue (It is not working for me either). Have you set the integration in debug mode ? Settings > devices & services > Netatmo > enable debug logging let it run for 1 day and click again on “disable debug logging” it will download a log file….. this is the last thing we can try, I’m blind here for the debug.

Iz-No-Good commented 1 week ago

I feel less lonely 😉…Still, i do not fet how it can work if the webhook is not working ? How do tou then get any data ??? Sure, i enable it tomorrow morning and post it either tomorrow night or Tuesday morning.

On Sun, Jun 23, 2024 at 21:48, tmenguy @.***> wrote: The webhook part is not an issue (It is not working for me either). Have you set the integration in debug mode ? Settings > devices & services > Netatmo > enable debug logging let it run for 1 day and click again on “disable debug logging” it will download a log file….. this is the last thing we can try, I’m blind here for the debug.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

tmenguy commented 1 week ago

The webhook is not used to fetch the data at all, It is to be alerted of state changes by the netatmo servers. So for energy probing (and other status) it is not mandatory.

Iz-No-Good commented 1 week ago

Hello @tmenguy , Looking more into the 'debug' log, I see a message coming regularly:

2024-06-26 08:21:11.619 DEBUG (MainThread) [custom_components.netatmo.pyatmo.auth] The Netatmo API returned b'{"error":{"code":9,"message":"Device not found"}}' (404) 2024-06-26 08:21:11.621 DEBUG (MainThread) [custom_components.netatmo.data_handler] fetch error ApiError: 404 - Not found - Device not found (9) when accessing 'https://api.netatmo.com/api/getmeasure'

So as you mentioned, it is like the index to define which 'sub-device' to query is not passed along.

Is there a way I can share my logs with you without sharing it here ?

tmenguy commented 1 week ago

Hi,

great, we do progress! You can reach me on discord (same name as GitHub), I use it from time to time.

BR Thomas

Iz-No-Good commented 1 week ago

Hello, Send you a invite (from too.late.9197)

Iz-No-Good commented 1 week ago

Hi, Thinking of the error, I would guess that what is missing, is the argument for /getmeasure to know which module to query (#0 to #8):

image
tmenguy commented 5 days ago

Reached back on discord if you want

yop190 commented 2 days ago

Hi,

Maybe I can add my two cents, because I made the integration for HCL last month ;)

About the parameters of /getStatus API. The device ID, it's the bridge (ex : "00:04:74:12:49:7e") The module ID, it's the ID (ex: "00:04:74:12:49:7e#1") And, you need to make a specific call for each device get from the homestatus.

Please, find the example of code below in lua (for HCL) ` local url = "https://api.netatmo.com/api/getmeasure?device_id="..deviceID.."&module_id="..moduleID.."&scale=1day&type=sum_energy_elec,sum_energy_elec%240,sum_energy_elec%241,sum_energy_elec%242&date_begin="..MyEcometerSensor:getTodayDate()

Netatamo:getNetatmoResponseData(url, requestbody, function(getData) local sumKw = 0 for , el in ipairs(getData.body) do for _ , v in ipairs(el.value) do -- Add all sum_energyelec to get all energy consume for the device -- Fibaro don't make the difference if you have tariff pic or not for , v2 in ipairs(v) do if tools:isNumber(v2) then sumKw = sumKw + v2 end end end end self:setValue("value",sumKw/1000) tools:debug(self:getVariable("moduleID") .. " : sum KW = " .. sumKw) end) end `

I contacted legrand/netatmo support because for now you can't have acces with homestatus and homedata the same fields when the api is consumed by an API token or user token (like consumption_type":"electrical" or "measures_scope":"total") The guy sound interesting to open this fields for API too but not for short term.

Sample :

So you need to hardcode it,

0-#4=> consumption_type":"electrical" & "measures_scope":"device"

:#5 => consumption_type":"electrical" & "measures_scope":"total" :#6 => consumption_type":"fluid" & "measures_scope":"device" & source_type= "gas" :#7 => consumption_type":"fluid" & "measures_scope":"device" & source_type= "hot_water" :#8 => consumption_type":"fluid" & "measures_scope":"device" & source_type= "cold_water"

For the #4 or #5, that depend how you have configured the sensor 5 in the ecometer.

On my side, I'm suck on HCL because the ecometer send historical informations each 3 hours ... So, for now I haven't nice graph in Fibaro or in HA using Fibaro integration ;) Indeed, in fibaro, I can't rewrite the history on consumption for the last 3 hours. So I have only a bar each 3 hours with the sum of the consumption for this duration. I hope in HA, you can rewrite the history of the last 3 hours.

I hope it will help you a bit. Cheers

tmenguy commented 1 day ago

@Iz-No-Good : not sure you seen discord, got an update for you to try out, if ok I'll fix it permanently