How to trigger automation on event sent by netatmo presence camera?

I build a bit further on this example, wanted to have the Netatmo presence detecton inform HA once I’m home. Using the Netatamo events for this.

Created two template sensors to filter out the Person-IDs, as I noticed sometimes my welcome camara sees two faces at the same time.:

netatmo_person_id0:
friendly_name: 'Netatmo Person'
value_template: '{%- if state_attr("sensor.netatmo_webhook", "persons") != None %}{{state_attr("sensor.netatmo_webhook", "persons")[0]["id"]}}{% endif %}'
netatmo_person_id1:
friendly_name: 'Netatmo Person'
value_template: '{%- if state_attr("sensor.netatmo_webhook", "persons") != None %}{%- if state_attr("sensor.netatmo_webhook", "persons")|length > 1 %}{{state_attr("sensor.netatmo_webhook", "persons")[1]["id"]}}{% endif %}{% endif %}'

Created an automation to inform HA presence that I’m home, based on my unique person ID code from Netatmo.

- alias: Y Occupancy On
  trigger:
  - entity_id: sensor.netatmo_person_id0
    platform: state
    to: 'fe73d1bc-2230-4de7-03a903c8940d'
  - entity_id: sensor.netatmo_person_id1
    platform: state
    to: 'fe73d1bc-2230-4de7-03a903c8940d'
  action:
  - data:
      payload: home
      topic: location/y
    service: mqtt.publish
1 Like

Hey Giel, I tried to use your “binary movement sensor”

but on checking config there’s something invalid:

Invalid config for [sensor.template]: value is not allowed for dictionary value @ data['sensors']['netatmo_webhook_trigger']['device_class']. Got 'motion'. (See ?, line ?).

Are there any changes at device_class in the mean time?

I’m desperate. I just can’t make the netatmo webhooks work. Found this in my logs:

## Log Details (ERROR)

Logger: homeassistant.components.netatmo
Source: components/netatmo/__init__.py:142
Integration: netatmo ([documentation](https://www.home-assistant.io/integrations/netatmo), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+netatmo%22))
First occurred: 8:58:58 PM (1 occurrences)
Last logged: 8:58:58 PM

Error during webhook registration - 400 - Bad request - Allowed ports for webhooks are 443 and 80. (21) when accessing 'https://api.netatmo.com/api/addwebhook'

The mentioned ports are free in my router.
Is there anybody who can help?

I also have problems to get MQTT run (see my post above). I´m completely new at MQTT.
I added

mqtt:

to my configuration.yaml and installed “Mosquitto Broker” add-on. Is my device_class problem an mqtt-problem?

Sorry, but it`s all new for me. :expressionless:

Did you follow the instructions in the documentation? Did you double check the http config in your configuration.yaml? Do you use a reverse proxy?

Hey Tobi, my http config is

http:
 base_url: !secret http_base_url
 ssl_certificate: /ssl/fullchain.pem
 ssl_key: /ssl/privkey.pem

http_base_url: https://xxx.ddns.net:8123

I don’t use a reverse proxy.

Yes, I followed instructions but I’m not sure if everything is allright. I’ve done my best. Have you any hints what I can look for? Which docu do you mean exactly? So much new stuff for me. It’s a little bit confusing.

Hi,
If you access specifying the 8123 port, that means that you redirected that port to your home Assistant on your router? Did you also redirect port 443 and/or 80? This is requested for the webhook.
Cheers

1 Like

Sorry for the late response, I’ still using the same config.
I use binary_sensor: !include_dir_merge_list devices/binary_sensors in my configuration.yaml
And the I have a netatmo.yaml file in that directory which contains

  - platform: template
    sensors:
      netatmo_webhook_trigger:
        device_class: motion
        friendly_name: Netatmo webhook trigger
        value_template: "{{ is_state('sensor.netatmo_webhook_trigger', 'NOC-human') }}"

Just to clarify, this thread predates the current implementation of the webhook based Netatmo event. Please be aware things have changed quite a bit and make sure you read the documetation.

Yes, I do! But reading something is often not the same as understanding. Webhooks und MQTT is completely new for me. I try my best. But seems it´s not enough. :sleepy:

Please check what @vlebourl asked you.

Updated my http-config :white_check_mark:
Updated port-forwarding in router :white_check_mark:
Followed instructions from Netatmo in HA 0.105 :white_check_mark:

=> Everythings works fine!!!

THANX!!! :grinning:

1 Like

Please, someone help me! I have been working on this for many days. I finally managed to make webhooks work! Now I get netatmo_event but I can’t use the webhook trigger.

- alias: Net2
  description: 'Motion detected at home'
  trigger:
  - event_type: netatmo_event
    platform: event
    event_data:
      type: movement # other possible types: animal, vehicle
  action:
    - service: persistent_notification.create
      data_template:
        notification_id: "movement"
        title: "Netatmo event"
        message: "movement"

This works!

  alias: Netatmo Webhook
  initial_state: 'on'
  trigger:
    platform: webhook
    webhook_id: netatmo_webhook
  action:
    - service: mqtt.publish
      data_template:
        topic: 'netatmo/update'
        retain: true
        payload_template: >
           {{ trigger.json | tojson }}

This doesn’t work, I don’t know what else to do!
my webhook URL: https://XXXXX.duckdsn.org/api/webhook/netatmo_webhook

The Netatmo webhook event is meant to be used in the way you show in the first example.

Thank you for your answer. So there is no way to do something like the second example :frowning_face:

Not sure what you prefer in the second example. If what you need is access to the trigger data, this is possible with {{ trigger.event.data }}. Here’s my own automation that creates custom notification on netatmo events:

- id: netatmoevent
  alias: Netatmo Event
  description: door or window is open or was moved
  trigger:
  - event_data: {}
    event_type: netatmo_event
    platform: event
  condition:
  - condition: template
    value_template: '{{ trigger.event.data.data.snap != "topology_changed" }}'
  action:
  - service: shell_command.get_image_and_resize
    data_template:
      name: '"{{ trigger.event.data.data.snapshot_id }}"'
      url: '{{ trigger.event.data.data.snapshot_url }}'
  - service: persistent_notification.create
    data_template:
      message: >-
        {{ trigger.event.data.data.message }}\n
        {% if trigger.event.data.data.snapshot_url %}
          ![image](/local/snapshots/{{trigger.event.data.data.snapshot_id}}.png)
        {% endif %}
      notification_id: '{{ trigger.event.data.data.message }}'
      title: >-
        Netatmo event:  
        {% if trigger.event.data[\"type\"] == \"tag_big_move\" %}
          Big Move
        {% elif  trigger.event.data[\"type\"] == \"tag_small_move\" %}
          Small Move
        {% elif  trigger.event.data[\"type\"] == \"tag_open\" %}
          Still Open
        {% else %}
          {{trigger.event.data[\"type\"]}}
        {% endif %}

Events are not fully documented in the HA documentation, but you already have several examples, and you can refer to the Netatmo API documentation for further details. To give credit to @cgtobi, Netatmo’s documentation is not very good, and a lot of what is known has been discovered through trials and errors. You can use the developper tool event listener to get the full content of the events you receive and adapt your automation accordingly.

2 Likes

Hi Francesco,

what exactly do you want to achieve? Just relay the event via mqtt?

Check if this simple relay of Netatmo events to MQTT is what you’re looking for.

I just noticed after playing with it that @gieljnssns had already posted an example which is actually linked in the cookbook as well.

@vlebourl @cgtobi
Thank you guys. Your directions was just what I needed. Thank you so much
It works fine

- alias: Netatmo Event
  description: door or window is open or was moved
  trigger:
  - event_data: {}
    event_type: netatmo_event
    platform: event
  action:
  - service: persistent_notification.create
    data_template:
      message: >
       {% if is_state('persistent_notification.netatmo' , 'notifying') %}
         {{ states.persistent_notification.netatmo.attributes.message }}
             [{{ now().strftime('%H:%M') }}] - Messaggio: {{ trigger.event.data.data.message }} - tipo evento: {{ trigger.event.data.data.event_type }}
       {% else %}
             [{{ now().strftime('%H:%M') }}] - Messaggio: {{ trigger.event.data.data.message }} - tipo evento: {{ trigger.event.data.data.event_type }}
       {% endif %}
      notification_id: "test"
      title: "ciccio"

  - service: mqtt.publish
    data_template:
      payload: '{{ trigger.event.data | tojson }}'
      retain: true
      topic: netatmo/update
1 Like

Hello guys. I would like to create an automatization based on the movement data from the Netatmo camera. I need to run a specific service if Netatmo camera detect a movement of human or animal, but I am totally beginner with this, so I have no idea how to „write this“ into configuration? I have working Netatmo integration where I am getting the video from the camera (in HA), but I don’t know how to „write“ this special condition? Could someone help me please?

you can use the event trigger listening to netatmo_event, and filtering according to {{trigger.event.data[\"type\"]}} for instance.

Have a look at previous posts to get examples.

Here’s an exemple of an event received from the welcome camera:

  event:
    event_type: netatmo_event
    data:
      type: movement
      data:
        user_id: xxxxREDACTEDxxxx
        event_type: movement
        camera_id: xxxxREDACTEDxxxx
        device_id: xxxxREDACTEDxxxx
        home_id: xxxxREDACTEDxxxx
        home_name: xxxxREDACTEDxxxx
        message: 'xxxxREDACTEDxxxx: Mouvement détecté par CamSalon'
        push_type: NACamera-movement
      device_id: xxxxREDACTEDxxxx
    origin: LOCAL
    time_fired: '2022-08-12T15:00:58.556991+00:00'
    context:
      id: 01GA9957HW35A6BAS5ZBC7H811
      parent_id: null
      user_id: null
  description: event 'netatmo_event'
2 Likes