docs: updated home assistant docs (#2459)

Co-authored-by: tomarm <a@a.com>
This commit is contained in:
TomArm 2023-07-24 05:54:49 +12:00 committed by GitHub
parent c86406e027
commit a75116bc62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,25 +1,77 @@
!!! info
This guide was submitted by a community member. Find something wrong? Submit a PR to get it fixed!
This guide was submitted by a community member. Find something wrong? Submit a PR to get it fixed!
In a lot of ways, Home Assistant is why this project exists! Since Mealie has a robust API it makes it a great fit for interacting with Home Assistant and pulling information into your dashboard.
### Get Todays Meal in Lovelace
Starting in v0.4.1 you are now able to use the uri `/api/meal-plans/today/image?group_name=Home` to directly access the image to todays meal. This makes it incredibly easy to include the image into your Home Assistant Dashboard using the picture entity.
### Display Today's Meal in Lovelace
Here's an example where `sensor.mealie_todays_meal` is pulling in the meal-plan name and I'm using the url to get the image.
You can use the Mealie API to get access to meal plans in Home Assistant like in the image below.
![api-extras-gif](../../assets/img/home-assistant-card.png)
Steps:
#### 1. Get your API Token
Create an API token from Mealie's User Settings page (https://hay-kot.github.io/mealie/documentation/users-groups/user-settings/#api-key-generation)
#### 2. Create Home Assistant Sensors
Create REST sensors in home assistant to get the details of today's meal.
We will create sensors to get the name and ID of the first meal in today's meal plan (note that this may not be what is wanted if there is more than one meal planned for the day). We need the ID as well as the name to be able to retreive the image for the meal.
Make sure the url and port (`http://mealie:9000` ) matches your installation's address and _API_ port.
```yaml
- platform: rest
resource: "http://mealie:9000/api/groups/mealplans/today"
method: GET
name: Mealie todays meal
headers:
Authorization: Bearer <<API_TOKEN>>
value_template: "{{ value_json[0].recipe.name }}"
force_update: true
scan_interval: 30
```
```yaml
- platform: rest
resource: "http://mealie:9000/api/groups/mealplans/today"
method: GET
name: Mealie todays meal ID
headers:
Authorization: Bearer <<API_TOKEN>>
value_template: "{{ value_json[0].recipe.id }}"
force_update: true
scan_interval: 30
```
#### 3. Create a Camera Entity
We will create a camera entity to display the image of today's meal in Lovelace.
In Home Assistant's `Integrations` page, create a new `generic camera` entity.
In the still image url field put in:
`http://mealie:9000/api/media/recipes/{{states('sensor.mealie_todays_meal_id')}}/images/min-original.webp`
Under the entity page for the new camera, rename it.
e.g. `camera.mealie_todays_meal_image`
#### 4. Create a Lovelace Card
Create a picture entity card and set the entity to `mealie_todays_meal` and the camera entity to `camera.mealie_todays_meal_image` or set in the yaml directly.
```yaml
show_state: true
show_name: true
camera_view: auto
type: picture-entity
entity: sensor.mealie_todays_meal
name: Dinner Tonight
show_state: true
show_name: true
image: 'http://localhost:9000/api/meal-plans/today/image?group_name=Home'
style:
.: |
camera_image: camera.mealie_todays_meal_image
card_mod:
style: |
ha-card {
max-height: 300px !important;
overflow: hidden;
@ -29,19 +81,5 @@ style:
}
```
The sensor that gets the name of the meal can be achieved using the following REST sensor in Home Assistant
```yaml
sensor:
- platform: rest
resource: 'http://localhost:9000/api/meal-plans/today'
method: GET
name: Mealie todays meal
headers:
Authorization: Bearer MySuperSecretBearerCode
value_template: "{{ value_json.name }}"
```
The Bearer token can be created from the User Settings page (https://hay-kot.github.io/mealie/documentation/users-groups/user-settings/#api-key-generation)
!!! tip
Due to how Home Assistant works with images, I had to include the additional styling to get the images to not appear distorted. This includes and [additional installation](https://github.com/thomasloven/lovelace-card-mod) from HACS.
Due to how Home Assistant works with images, I had to include the additional styling to get the images to not appear distorted. This requires an [additional installation](https://github.com/thomasloven/lovelace-card-mod) from HACS.