Netatmo in HA 0.105

When you ran the integration dialogue, did you select “configuration.yaml” or “HA Cloud”?

The webhook based event is called “netatmo_event”, just in case you’re listening for another one.

First time configuration.yaml as I still had some configuration in there for netatmo but got a plain-text error that the return url was not correct. Then tried HA Cloud and that didn’t give error. Since then I removed all netatmo items from configuration.yaml and since then I’m not getting the option anymore, it goes straight through the HA Cloud process.

You have to remove the integration, add Netatmo to your configuration.yaml and restart HA. Then you should be able to use that in the integrations dialogue.

Thanks for the advice @cgtobi! No succes, unfortunately. I removed everything and restarted. Added (and then restarted again):

netatmo:
  client_id:     !secret netatmo_client_id
  client_secret: !secret netatmo_client_secret

When adding the integration I’m getting the dialog for configuration.yaml or HA Cloud.

When chosing configuration.yaml option, I get send to Netatmo, authenticate and return at HA with a 500:

https://.ui.nabu.casa/auth/external/callback?state=<long_string>&code=<long_string>

500 Internal Server Error
Server got itself in trouble

The log in HA shows the following:

Log Details (ERROR)
Logger: aiohttp.server
Source: helpers/config_entry_oauth2_flow.py:167
First occurred: 7:35:57 AM (2 occurrences)
Last logged: 7:36:11 AM

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 418, in start
    resp = await task
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_app.py", line 458, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/real_ip.py", line 39, in real_ip_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 72, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 127, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 123, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 154, in get
    return await super().get(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 80, in get
    result = await self._flow_mgr.async_configure(flow_id)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 130, in async_configure
    result = await self._async_handle_step(flow, cur_step["step_id"], user_input)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 172, in _async_handle_step
    result: Dict = await getattr(flow, method)(user_input)
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 246, in async_step_creation
    token = await self.flow_impl.async_resolve_external_data(self.external_data)
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 142, in async_resolve_external_data
    "redirect_uri": self.redirect_uri,
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 167, in _token_request
    resp.raise_for_status()
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client_reqrep.py", line 946, in raise_for_status
    headers=self.headers)
aiohttp.client_exceptions.ClientResponseError: 400, message='', url='https://api.netatmo.com/oauth2/token

After this all, the integration is not added.

Then, when retry adding the integration but chosing the Home Assistant Cloud option, it works (Success! Successfully authenticated with Netatmo. Created configuration for Home Assistant Cloud. We found the following devices:) and I see my devices. But no images, and following state:

access_token: <access_token>
model_name: Presence
brand: Netatmo
motion_detection: true
id: <mac_address>
status: on
sd_status: on
alim_status: on
is_local: null
vpn_url: null
friendly_name: Netatmo Voorgevel
entity_picture: /api/camera_proxy/camera.netatmo_voorgevel?token=<access_token>
supported_features: 2

After that, the error “Welcome/Presence VPN URL is None” appears in the logs whenever I try to view the camera.

What I notice, by the way, is that when send to Netatmo for authentication, the ‘scope’ does not include: ‘access_presence’ and ‘access_camera’. Shouldn’t these be in scope? Those were in scope for the previous integration, which worked for me. I’m pretty sure this is causing the issue as I see what that scope authorizes for.

Can you please show me your http: section in your configuration.yaml?

It should be something like:

http:
  base_url: https://<your_unique_string>.ui.nabu.casa/

HA Cloud will support cameras in the future as we are in the process of getting HA certified by Netatmo but right now it does only work with individual dev accounts per user.

Understood to use the configuration.yaml option and not the HA Cloud option!

The http: section is exactly like you describe it (can copy-paste it but its exactly like your example code snippet).

I notice that the following error is also showing up in the logs when I hit the error 500 after authentication at Netatmo.

Log Details (ERROR)
Logger: aiohttp.server
Source: data_entry_flow.py:123
First occurred: 1:45:30 PM (3 occurrences)
Last logged: 1:46:06 PM

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 418, in start
    resp = await task
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_app.py", line 458, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/real_ip.py", line 39, in real_ip_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 72, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 127, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 123, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 374, in get
    flow_id=state["flow_id"], user_input=request.query["code"]
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 123, in async_configure
    raise UnknownFlow
homeassistant.data_entry_flow.UnknownFlow

HOWEVER! I fixed it :slight_smile: Might be that I have been an idiot,though (your call). What I did was I created a completely new app at dev.netatmo.com, next to the existing App which the previous HassIO integration was using. This did the trick. One small bug, though: after integration it noted ‘Success’ and showed me 1 camera was found, but there are 3 and I see that fortunately 3 have been added indeed, so it appears that only the Success message sees/shows 1 camera.

One question: what is the correct way to configure a trigger in automation for human event?

- alias: Outdoor camera motion detected
  trigger:
  - platform: event
    event_type: netatmo_event
    event_data:
      type: human
      camera_id: <camera_mac_address>
1 Like

Thanks for the feedback.

The success dialogue fills up over time as devices are discovered.

For the event usage, it looks alright. I haven’t tested the camera_id part, but here is an example:

- id: '1234567890123'
  alias: Motion at home
  description: 'Motion detected at home'
  trigger:
  - event_type: netatmo_event
    platform: event
    event_data:
      type: movement
  action:
  - data_template:
      message: >
        {{ trigger.event.data["data"]["message"] }}  
        at {{ trigger.event.data["data"]["home_name"] }}
      title: Netatmo event
    service: persistent_notification.create
1 Like

About the 500 error, you can check your app on dev.netatmo.com if it has been banned. That might cause issues.

That automation is not working for my Netatmo Presence as the

event_data:
  type: movement

is not working when the camera detects a human.

In that case you can replace movement with human:

event_data:
  type: human

I would suggest to react on all Netatmo events like in the automation below, as this will only be triggered by a detected motion of the camera isn’t it @cgtobi?

- id: '1234567890123'
  alias: Motion at home
  description: 'Motion detected at home'
  trigger:
  - event_type: netatmo_event
    platform: event
  action:
  - data_template:
      message: >
        {{ trigger.event.data["data"]["message"] }}  
        at {{ trigger.event.data["data"]["home_name"] }}
      title: Netatmo event
    service: persistent_notification.create

Below the output when I listen to netatmo_event where I changed private info with ---:

{
    "event_type": "netatmo_event",
    "data": {
        "type": "human",
        "data": {
            "user_id": "---",
            "snapshot_id": "---",
            "snapshot_key": "---",
            "snapshot_url": "https://netatmocameraimage.blob.core.windows.net/production/---",
            "vignette_id": "---",
            "vignette_key": "---",
            "vignette_url": "https://netatmocameraimage.blob.core.windows.net/production/---",
            "event_type": "human",
            "camera_id": "---",
            "device_id": "---",
            "home_id": "---",
            "home_name": "Thuis",
            "event_id": "---",
            "subevent_id": "---",
            "message": "Persoon gezien",
            "push_type": "NOC-human"
        }
    },
    "origin": "LOCAL",
    "time_fired": "2020-03-24T21:56:15.872428+00:00",
    "context": {
        "id": "---",
        "parent_id": null,
        "user_id": null
    }
}

Thanks @gerard33 for the feedback. You are totally right, movement wont work for presence/outdoor cameras. To capture movement outside you can use outdoor as an “umbrella” keyword if you want to act upon not only human but also for example cars and animals.

Thanks for the quick reply :+1:
I just tested it with this

trigger:
  - platform: event
    event_type: netatmo_event
    event_data:
      type: outdoor

but that didn’t work.
When I use:

trigger:
  - platform: event
    event_type: netatmo_event

so without any event_data it works fine, at least for human movement, but that should work for any movement.

Oh, sorry, you are right. outdoor is actually for when multiple things are detected in the scene, like animal and human.

I’d still suggest to use event_data + type but use multiple triggers for finer control. Like react to animals and humans only, but not cars for example. With just netatmo_event the automation would also react to smoke alarms (if you have them) for example or any other kind of event that the Netatmo API happens to send over that might not be relevant for that automation.

That’s a good suggestion indeed.
Based on the previous binary_sensors I would say the following event_data types are possible for a Presence:

  • motion -> or should we use outdoor for this now?
  • human
  • vehicle
  • animal
1 Like

Yes, here is the full (official) list: https://dev.netatmo.com/apidocumentation/security#events

In case an outdoor event is triggered, there will be the outdoor event itself but also an event for every subevent fired in HA.

Thanks. I didn’t see the outdoor event when the human trigger happened though, but using the subevents will be working fine.

1 Like

Did some testing with the triggers for the Netatmo Presence and these are really fast with the new solution you have implemented. I see an update in HA just before the Netatmo app gives me a message. Nice work :+1: and looking forward to the light implementation.

Using the events I have enabled binary sensors again which work as presence detection. If anyone is interested, here is the code.
First make input_boolean entities like this:

# Netatmo motion detection
netatmo_motion_human:
 name: Netatmo detected a person
 initial: off
 icon: mdi:motion-sensor
netatmo_motion_vehicle:
 name: Netatmo detected a car
 initial: off
 icon: mdi:car
netatmo_motion_animal:
 name: Netatmo detected an animal
 initial: off
 icon: mdi:dog

And then binary_sensor templates which use the status of the input_boolean entities:

# Netatmo camera presence detection
- platform: template
  sensors:
    netatmo_motion_human:
      friendly_name: "Netatmo beweging persoon"
      device_class: motion
      value_template: >-
        {{ is_state('input_boolean.netatmo_motion_human', 'on') }}
    netatmo_motion_vehicle:
      friendly_name: "Netatmo beweging auto"
      device_class: motion
      value_template: >-
        {{ is_state('input_boolean.netatmo_motion_vehicle', 'on') }}
    netatmo_motion_animal:
      friendly_name: "Netatmo beweging dier"
      device_class: motion
      value_template: >-
        {{ is_state('input_boolean.netatmo_motion_animal', 'on') }}

And use these automations to use the new triggers to switch on the input_booleans and switch them off after 2 minutes (you can of course change this delay):

- alias: input_boolean to on if Netatmo camera detects a person
  trigger:
    - platform: event
      event_type: netatmo_event
      event_data:
        type: human
  action:
    - service: input_boolean.turn_on
      entity_id: input_boolean.netatmo_motion_human
    - delay: '00:02:00'
    - service: input_boolean.turn_off
      entity_id: input_boolean.netatmo_motion_human
- alias: input_boolean to on if Netatmo camera detects a vehicle
  trigger:
    - platform: event
      event_type: netatmo_event
      event_data:
        type: vehicle
  action:
    - service: input_boolean.turn_on
      entity_id: input_boolean.netatmo_motion_vehicle
    - delay: '00:02:00'
    - service: input_boolean.turn_off
      entity_id: input_boolean.netatmo_motion_vehicle
- alias: input_boolean to on if Netatmo camera detects an animal
  trigger:
    - platform: event
      event_type: netatmo_event
      event_data:
        type: animal
  action:
    - service: input_boolean.turn_on
      entity_id: input_boolean.netatmo_motion_animal
    - delay: '00:02:00'
    - service: input_boolean.turn_off
      entity_id: input_boolean.netatmo_motion_animal
3 Likes

Thanks @gerard33 for the kind feedback and the great example.

1 Like

Was the “Light Implementation” dropped? I noticed it went “Stale” and then “Cancelled” :frowning:

No, but it was not the right approach and needs more work.

value is not allowed for dictionary value @ data['sensors']['netatmo_motion_animal']['device_class']. Got 'motion'

I’m getting config parse fail on this. Had to remove the device_class line, any idea why ?

EDIT: found the error, I had made a sensor, not a binary_sensor