TawfikDaim / home_automation

home automation user stories
0 stars 0 forks source link

Notification by whatsapp #90

Closed TawfikDaim closed 1 month ago

TawfikDaim commented 1 month ago

Dependency: home assistant needs to be accesible from outside to be able to attach the image, here the location of the image must be inside www folder and will eb accessed as 'http://your-home-assistant-url/local/motion_3.jpg'

Follow steps below...(https://github.com/t0mer/green-api-custom-notifier)

login to https://console.green-api.com get you API key from greenapi project configure whatsapp number The free account is limited to 3 chats (Group or Private). go to API/ServiceMethods/GetContacts to get list of contacts and groups (mark the id of the target group to send notifications to) { "id": "120363345070380596@g.us", "name": "Notifications ", "type": "group" }, Download the green-api-custom-notifier, place it under the custom_components folder. Restart Home Assistant and add the following section to your configuration.yaml file: notify:

TawfikDaim commented 1 month ago

to save a snap chat once a motion is detected

use this code in the automation before sending the picture


action: camera.snapshot
target:
  entity_id: camera.maindoor
data:
  filename: /config/www/snapshots/maindoor_latest.jpg

to send the last stored picture to the whatsapp use this code

data:
  target: 201201971120-1630483083@g.us
  message: Motion detected at main door
  data:
    file: /config/www/snapshots/maindoor_latest.jpg
action: notify.greenapi

full automation script is here

alias: Motion Detected at Main Door by Camera/Frigate
description: ""
triggers:
  - entity_id: binary_sensor.maindoor_motion
    to: "on"
    trigger: state
conditions: []
actions:
  - sequence:
      - action: camera.snapshot
        target:
          entity_id: camera.maindoor
        data:
          filename: /config/www/snapshots/maindoor_latest.jpg
  - data:
      target: 201201971120-1630483083@g.us
      message: Motion detected at main door
      data:
        file: /config/www/snapshots/maindoor_latest.jpg
    action: notify.greenapi
mode: single
TawfikDaim commented 1 month ago

full automation after adding condition to check for motion in day using person count and at night using motion sensor

STILL UNDER TESTING

alias: Motion Detected at Main Door by Camera/Frigate
description: ""
triggers:
  - entity_id: binary_sensor.maindoor_motion
    to: "on"
    trigger: state
    id: Motion_detected_at_night_usingSensor
  - entity_id:
      - binary_sensor.maindoor_person_occupancy
    trigger: state
    id: Motion_detected_at_day_usingPersonCount
    to: "on"
conditions: []
actions:
  - if:
      - condition: sun
        after: sunset
        before: sunrise
      - condition: and
        conditions:
          - condition: trigger
            id:
              - Motion_detected_at_night_usingSensor
    then:
      - action: camera.snapshot
        target:
          entity_id: camera.maindoor
        data:
          filename: /config/www/snapshots/maindoor_latest.jpg
      - delay:
          hours: 0
          minutes: 0
          seconds: 1
          milliseconds: 0
      - data:
          target: 201201971120-1630483083@g.us
          message: Motion detected at main door
          data:
            file: /config/www/snapshots/maindoor_latest.jpg
        action: notify.greenapi
    else:
      - condition: sun
        before: sunset
        after: sunrise
      - condition: trigger
        id:
          - Motion_detected_at_day_usingPersonCount
      - action: camera.snapshot
        target:
          entity_id: camera.maindoor
        data:
          filename: /config/www/snapshots/maindoor_latest.jpg
      - delay:
          hours: 0
          minutes: 0
          seconds: 1
          milliseconds: 0
      - data:
          target: 201201971120-1630483083@g.us
          message: Motion detected at main door
          data:
            file: /config/www/snapshots/maindoor_latest.jpg
        action: notify.greenapi
mode: single