Are you sure? This is still working for me:
Please make sure you are using the “deprecatedToken”. The thing_name is actually “m-” followed by the feeder MAC address that you can find in the app under Feeder Details.
Are you sure? This is still working for me:
Please make sure you are using the “deprecatedToken”. The thing_name is actually “m-” followed by the feeder MAC address that you can find in the app under Feeder Details.
Just in case you still had this problem, for me I traced it back to a very annoying issue of the “Token” key in headers of the request not being capitalized:
{'token':'myTokenHere'}
instead of
{'Token':'myTokenHere'}
If this isn’t formatted properly in the request, one of the errors you can get is the weird Smartfeed App error.
Even more frustrating, if you were using the Pyscript add-on and the python PetSafe Smartfeed repo on GitHub, the capitalization still needs to be corrected there…and…there’s some weirdness with Pyscript lowercasing the header key, but only when methods are called from an import…
I gave up on the pyscript thing and am just using rest-commands now…
Interested in picking one of these up. Is this integration using deprecated tokens still working? Thanks!
Yes still working as far as I am aware, although this is not an integration as such but a way to build your sensors / rest_commands. Follow the instructions from @afishe2000 to get the Token (also summarised below):
curl --request POST \
--url https://users-api.ps-smartfeed.cloud.petsafe.net/users/ \
--header 'Content-Type: application/json' \
--data '{ "email": "[email protected]" }'
curl --request POST \
--url https://users-api.ps-smartfeed.cloud.petsafe.net/users/tokens \
--header 'Content-Type: application/json' \
--data '{ "email": "[email protected]", "code": "XXX-XXX" }'
curl --request GET \
--url https://api.ps-smartfeed.cloud.petsafe.net/api/v2/feeders \
--header 'Content-Type: application/json' \
--header 'Token: yourtoken'
Once you done this it’s time to play. Feel free to use anything from my example below (under configuration.yaml)
# Petsafe #
rest_command:
feed_the_tigers:
method: post
verify_ssl: false
url: "https://api.ps-smartfeed.cloud.petsafe.net/api/v2/feeders/THING_NAME/meals"
headers:
Content-Type: application/json
Token: !secret petsafe_token
payload: '{"amount": "1"}'
rest:
- authentication: basic
scan_interval: 310
resource: https://api.ps-smartfeed.cloud.petsafe.net/api/v2/feeders/THING_NAME/messages?days=1
headers:
Content-Type: application/json
Token: !secret petsafe_token
sensor:
- name: "Petsafe Notification"
value_template: "{{ state_attr('sensor.petsafe_notification', 'message_type') }}"
json_attributes:
- "message_type"
- "created_at"
- "payload"
Important note: for the above rest command don’t use a lower “scan_interval” as Petsafe only allows pinging their server with a frequency equal or above 5 minutes
vacuum:
- platform: template
vacuums:
pet_feeder:
friendly_name: Pet feeder
start:
- service: rest_command.feed_the_tigers
value_template: >-
{% if states('sensor.petsafe_notification').lower() == 'unknown' %}
error
{% else %}
docked
{% endif %}
battery_level_template: >-
{{ (state_attr('sensor.petsafe_notification', 'payload').sensorReading1Infrared*100/29396)|round}}
attribute_templates:
notification: "{{ states('sensor.petsafe_notification') }}"
food_level: "{{ states('sensor.food_level') }}"
last_feed: "{{ as_timestamp(state_attr('sensor.petsafe_notification', 'created_at'))|timestamp_custom('%I:%M%p %d/%m/%y') }}"
payload: "{{ state_attr('sensor.petsafe_notification', 'payload') }}"
# Petsafe sensors #
- sensor:
- name: "Petsafe last feed"
state: "{{ as_timestamp(state_attr('sensor.petsafe_notification', 'created_at'))|timestamp_custom('%I:%M%p %d/%m/%y') }}"
- sensor:
- name: "Food level"
state: >
{% set food_level = state_attr('sensor.petsafe_notification', 'payload') %}
{% if food_level.isFoodLow == 2 or states('sensor.petsafe_notification') == "FOOD_EMPTY" %}
Feeder is empty!
{% elif food_level.isFoodLow == 1 %}
Feeder is almost empty!
{% else %}
Feeder is full
{% endif %}
- sensor:
- name: "Food level %"
state: >
{% set food_level = state_attr('sensor.petsafe_notification', 'payload') %}
{% if food_level.isFoodLow == 2 %}
10
{% elif states('sensor.petsafe_notification') == "FOOD_EMPTY" %}
0
{% else %}
{{ (state_attr('sensor.petsafe_notification', 'payload').sensorReading1Infrared | float *100 / 29396) | round(1) }}
{% endif %}
unit_of_measurement: "%"
Hope this helps
Thanks so much for the details response @Zeunas. This seems like it should work for my intended purpose. I mainly want to be able to just monitor in HA that it is feeding the cat as planned for when we are gone for multiple days. It appears this route still maintains all the standard functionality of the original app (unlike some of the other esp based implementations I’ve seen on the Tuya/SmartLife feeders that replaces the factory firmware entirely, which I’d like to avoid for reliability sake.)
One last question, how are these devices about keeping time? I would assume with WiFi they are doing some form of time correction every now and then? My biggest annoyance of other non-connected auto feeders is really significant time drift. I really just want to make sure kitty gets fed routinely and reliably when on vacation and have HA notify me if it cannot confirm a feeding happened within the last X hours.
Exactly! You can still use the Petsafe app as normal. Assume you don’t have the feeder yet but you can probably install the app and create an account to test the points 1 - 3 to get your token.
Not sure if I understand your question, I mean once you set up your feeding schedule on the app (or even home assistant via automations), the feeding timing is pretty reliable. Although with this set up on home assistant you may have a delay up to 5 minutes from the point the food is dispensed to get the updated “Last feed” information, due to the “scan_interval” limitation I mentioned above. There’s another annoying thing which is the Winter time vs Summer time, the API doesn’t seem to update to Summer time, so at the mo it’s telling me the last feed was an hour earlier than scheduled, which it wasn’t - You may be able to fix it with a template. I just haven’t thought much about it because it doesn’t really affect the purpose of these sensors, as long as I know my cats have been fed in the last couple of hours. Hope this answers your question.
Ah I see. So if I understand correctly, while the feeder is still feeding at the right time, the reporting is incorrect due to sensor not accounting for DST. That’s not a huge concern, and as you noted maybe fixable with a template sensor. I’m less concerned with having HA aware of a feeding within minutes, or even hours, and moreso being able to raise an alert if it’s been half a day or a day and HA can’t confirm kitty was fed.
My issue with the feeder I have currently is quite literally over a period of weeks or months the internal clock will drift so much so that the feedings will eventually become an hour or more later from the intended (actual) time because of the ever increasingly incorrect device clock. I would think connected devices could easily correct this via NTP or some other solution within the software.
In that case I can confirm that you don’t need to worry about time drifting with the petsafe feeder at all. The only “concerns” you will have is to top it up when needed, although the feeder holds almost 6 L of food, and power cuts (which you can prevent with the backup battery option it has).
Awesome. Thanks so much for your help. Ordering one today.
Thanks again so much @Zeunas .
I got the feeder setup and working in HA using your first two code blocks (rest_command and rest). I tried adding the third for the sensors and it gave me an error ( Invalid config for [vacuum]: required key not provided @ data[‘platform’]. Got None.). I think because this needs to be below an existing template sensor section in the code, still playing around with it.
I noticed it shows battery percentage. This has showed 25% for me before and after installing batteries in the device. Does the battery level server any purpose? Food level is still showing unknown for me although the app now shows it is no longer low. And to your point about the time info on the sensor, mine showed 11:00pm after a 6:00pm feeding (which tells me it’s likely based on UTC time since I am UTC-5). Like you said, I think that could be handled via a template maybe. Feeding definitely works though and it is receiving the notifications from PetSafe cloud. I probaly just need to mess around with the code a bit more and get it just how I wawnt but this is really close. Thanks again!
Good one! Glad it´s working for you!
Yes, for this you will need the below sensor (forgot to mention when I 1st shared my config that you need to add the “template:” line before the sensor but if your vacuum attributes are working I assume you worked that out ). Feel free to share your config I’ll try my best to help, although I’m not an expert a lot is trial an error and you may find that you can simplify my config further
template:
- sensor:
- name: "Food level"
state: >
{% set food_level = state_attr('sensor.petsafe_notification', 'payload') %}
{% if food_level.isFoodLow == 2 or states('sensor.petsafe_notification') == "FOOD_EMPTY" %}
Feeder is empty!
{% elif food_level.isFoodLow == 1 %}
Feeder is almost empty!
{% else %}
Feeder is full
{% endif %}
Ah yes! There´s quite a big chunk of information I have not shared on my summary, you may want to have a read through the initial post from @afishe2000 (here) where he shows the details you can get from the rest sensor and depending on the level of information you want on your rest sensor you may want to add a few more “json_attributes”. For the purpose of having battery percentage you will need to add “battery_voltage” to json_attributes and then create a sensor such as the one shared by @j6s33m (here). I should also mention that I don’t have batteries on my feeder and the battery % you see it’s the actual food level (my bad for not telling you earlier), so once you create your battery sensor you just need to update the name on the sensor under the vacuum template. If you still want to keep a food level % sensor you can add it to the attributes of the vacuum template instead.
Try adding " - timedelta(hours = 5)" to the last_feed attribute template of the vacuum, like below (you may find a better template to take into account DST, do share if you find it ) :
last_feed: "{{ (as_timestamp(state_attr('sensor.petsafe_notification', 'created_at')) - timedelta(days = 1))|timestamp_custom('%I:%M%p %d/%m/%y') }}"```
Okay this helped a lot actually. I still banging my head on the time/timezone issue. The timedelta thing doesn’t work as intended yet. I think I can figure this out eventually, just gonna take a lot of trial and error for me. It seems like time manipulation in HA is entire rabbit hole all on it’s own lol. Thanks again for all your help though, I learned quite a bit through your examples in regards to rest in HA and manipulating data into sensors, so thanks for that! I will let you know once I finally figure it out.
That’s the beauty of HA for me and finding the solution is the best reward (in addition to be able to help others when they get stuck). Good luck!
Hiya, just revisiting this old post and was wondering how did you manage to use Pyscript add-on back then? It seems that the Petsafe Smartfeed repo uses a new Petsafe API, which for now has only affected my ability to send a command to drop some food but I have a feeling that the deprecatedToken old API will eventually stop working…
I still have work to do, but I’m in the process of building a HACS integration for both the feeders and litter boxes. Never build an HA integration before so I’m sure it’s not perfect and probably has bugs, but I’m learning! I should have it in HACS within a week or so
Thought about doing too but not savvy enough and I only have the feeder. Let me know once you release, happy to be a tested.
It’s not quite perfect and I’m sure there are some bugs but it’s working for me so if you want to give it a try, GitHub - dcmeglio/homeassistant-petsafe
Simple and easy to set up! Working fine with my feeder, thanks! Is this based on the new API they’ve released a while ago? The one they don’t use the deprecated token.
Perhaps you could include a food level % based on the two infrared sensors the feeder has.
What does the Feeding Paused switch do? Wasn’t aware of it.
Going to keep an eye on it and will let you know is something goes wrong or if I have any suggestions. Great work so far!
Nevermind, just checked and I can see it’s based on the new API. Super!
It will report if the food is full/low/empty with the Food Level entity. I’m not totally sure how to interpret the values that come back from the sensors so I’m not sure how to make it more accurate than that.
It lets you temporarily pause your feeding schedules