This is an upgrade for Home Assistant Facebook integration. It allows you to send notification to Messenger with images.
- Functionality
- Installation
- Configuration
- How to obtain your Facebook token
- Hot to obtain your user's PSID
- Installation and Configuration Summary
- Usage
- License
This integration is based on Facebook integration currently available in Home Assistant. It's possible to send text-based and image notifications. You can also assign names to your SIDs and use it as notification target.
HACS is the preferred installation method. Click here, you'll be
redirected to your Home Assistant instance. If link doesn't work, you can find Facebook Messenger
in HACS integrations repository list.
Manual method. Copy the facebook_messenger
folder into the config\custom_components
folder of your Home Assistant instance, and restart.
This integration exposes itself as a notifications integration, and can be configured by adding this snippet in your configuration.yaml
file:
notify:
name: messenger
platform: facebook_messenger
page_access_token: <YOUR FACEBOOK TOKEN>
targets:
- sid: <YOUR PSID>
name: mike
Replace <YOUR FACEBOOK TOKEN>
with your facebook token, use secrets.yaml for better protection.
targets
attribute is optional. If you declared it, you can use human readable names instead of digits as your notification's target.
Restart Home Assistant to load your configuration.
To use this integration you must register as Facebook developer and create application that will be
sending notifications on your behalf. First login to your Facebook account and click here to start registration process. It requires few steps, you must confirm your phone and email address, choose occupation (use developer 😉).
When you've done with registration process, add new application.
- Choose app type Business
- Choose Display name, enter your email and click Create App. You'll have to enter password again.
- On the next page Add products to your app find Messenger tile and click Set up.
- Find Access Tokens section and click Create new Page, new tab will open, keep this one open, you return here in steps 7 and 10
- Provide Name and Category, you may choose whatever you like, but Name must be unique.
- Click next until you reach Ready page, you don't have to provide any additional information
- Return to Access Tokens tab, and this time click Add or remove Page, new window opens
- Confirm that it's really you, check Page you've just created, and click Next
- Ignore warning and click Ready!, your page is connected with Facebook
- Return to Access Tokens tab again, now click Generate token, check I understand,
- Success 💪 finally you have your token, copy and save it
This part is quite tricky, hope you can get through this. As using phone numbers is not an option nowdays, this is the only way to get things working. To find your (or your testers) PSID you have to assign webhook to your page, that webhook will reply with your PSID. Let's start.
- For creating webhook we'll use glitch.com, you don't need to register there
- Open my project get-messenger-page-sid and click
Remix
- New project is created, on the left you have file manager, click
.env
- Paste your Facebook Access Token as PAGE_ACCESS_TOKEN variable value
- Put value of your choice into VERIFY_TOKEN value, exactly the same value you enter at Facebook, step 10
- At the bottom of the screen click
PREVIEW
thenOpen preview pane
- Preview opens on the right side, you'll see url ex.
observant-foregoing-scent.glitch.me/
, open menu and clickCopy Link
- Now go to your facebook developer dashboard https://developers.facebook.com/apps/, and click your app
- On the left menu click
Messenger
,Settings
, findWebhooks
section, clickAdd Callback URL
- Paste your glitch url here, append
/webhook
at the end so full url looks something likehttps://observant-foregoing-scent.glitch.me/webhook
, enter your verify token, clickVerify and save
- You should see your webhook added, click
Add subscriptions
and selectmessages
- Your webhook is ready, now use Messenger to send any message to your page, it replies with your PSID
Quick summary to get things working:
- Install facebook_messenger integration
- Reboot Home Assistant
- Create a
notify
entity, use your facebook page token - Reboot Home Assistant
- Start adding the new entity to your automations & scripts :)
action:
- service: notify.messenger
data:
target: mike
message: "Hello from Home Assistant."
action:
- service: notify.messenger
data:
target: mike
data:
media: "<path to image file on server>"
media_type: "image/jpeg"
It is important to specify correct media_type
. It is validated by Facebook and message will be rejected when media_type
doesn't match actual media file type. image/jpeg
is default value.
You can also test it in Developer Tools, under Services tab.
This software is released under the MIT license.