Open twcau opened 1 year ago
Hey there @postlund, mind taking a look at this issue as it has been labeled with an integration (apple_tv
) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)
apple_tv documentation apple_tv source (message by IssueLinks)
These are only available via HomeKit and will thus not be exposed via the Apple TV Integration as pyatv does not support HomeKit (and I don't plan to support it either).
To be able to add these to HomeKit, they would need to be unpaired first. Conceptually, this just does not make sense so I don't think that there would be any way for us to do that.
To integrate HomePod Mini sensors into Home Assistant when direct integration isn't possible, you can use the following method:
Create an input_boolean
that will be exposed to HomeKit:
input_boolean:
homekit_sensors_update:
name: Collection of HomeKit sensors
initial: off
Include this input_boolean
in the HomeKit configuration:
homekit:
- name: your House
port: 56320
filter:
include_entities:
- input_boolean.homekit_sensors_update
Create input_number
for the sensors:
These entities will store the sensor values.
input_number:
homepodmini_XXXXX_temperature:
name: "HomePodMini XXXXX temperature"
initial: 21
min: 0
max: 100
unit_of_measurement: "°C"
homepodmini_XXXXX_humidity:
name: "HomePodMini XXXXX humidity"
initial: 50
min: 0
max: 100
unit_of_measurement: "%"
Create sensors in Home Assistant:
These sensors will use the input_number
to display data.
sensor:
- platform: template
sensors:
homepodmini_XXXXX_temperature:
friendly_name: "Living Room"
unit_of_measurement: '°C'
value_template: "{{ states('input_number.homepodmini_XXXXX_temperature') }}"
icon_template: mdi:thermometer
homepodmini_XXXXX_humidity:
friendly_name: "Living Room"
unit_of_measurement: '%'
value_template: "{{ states('input_number.homepodmini_XXXXX_humidity') }}"
icon_template: mdi:water-percent
Create an automation in Home Assistant:
This automation will update the input_number
based on data received via a webhook and will activate the input_boolean
to request an update to HomeKit.
- id: update_homekit_sensors
description: Process temperature and humidity from HomePod Mini
trigger:
- platform: webhook
webhook_id: homekit_sensors
allowed_methods:
- POST
local_only: true
id: WebHook
- platform: time_pattern
minutes: /2
id: time
action:
- choose:
- conditions:
- condition: trigger
id:
- WebHook
sequence:
- service: input_number.set_value
data_template:
entity_id: input_number.{{ trigger.json.sensor }}_temperature
value: '{{ trigger.json.temperature }}'
- service: input_number.set_value
data_template:
entity_id: input_number.{{ trigger.json.sensor }}_humidity
value: '{{ trigger.json.humidity }}'
- conditions:
- condition: trigger
id:
- time
sequence:
- service: input_boolean.turn_on
data: {}
target:
entity_id: input_boolean.homekit_sensors_update
- delay:
hours: 0
minutes: 0
seconds: 5
milliseconds: 0
- service: input_boolean.turn_off
data: {}
target:
entity_id: input_boolean.homekit_sensors_update
mode: parallel
max: 10
Set up an automation in the HomeKit app:
This automation will trigger when homekit_sensors_update
is activated. It will obtain temperature and humidity values and send this data to Home Assistant via the URL http://homeassistant:8123/api/webhook/homekit_sensors
using the POST method with a JSON containing the sensor data.
Format of the JSON to send:
{
"sensor": "XXXXX",
"temperature": temperature value,
"humidity": humidity value
}
This method allows you to bypass the limitations of direct integration of HomePod Mini sensors into Home Assistant by using HomeKit as an intermediary.
Thanks @FermedePommerieux, this method works quite well!
However, the humidity value only gets correctly populated when I manually test the automation from the HomeKit app, otherwise it registers as 0.0%.
edit: I got it working, for some reason the Home automation was using the "Current state" variable instead of "current relative humidity". Weird that it worked when manually triggering...
Ensure your HomeKit automation is correctly set to use the 'current relative humidity' attribute from your HomePod Mini's humidity sensor. Also, verify that the automation triggers as expected. I've successfully implemented this method with three HomePod Minis, so these checks should help resolve the issue.
Hello! Thanks for the awesome tips, following the instructions in ran into a little issue that I'm surprised you didn't (or maybe I missed something?)
I could see the webhook incoming from Homekit in HASS but it is sending the data in the following format:
trigger:
platform: webhook
webhook_id: homekit_sensors
json:
sensor: homepodmini_bathroom
temperature: 21,2°C
humidity: '48'
I can see in the logbook:
Stopped because an error was encountered at 17 December 2023 at 00:28:01 (runtime: 0.01 seconds)
expected float for dictionary value @ data['value']
This is because the temperature
field is not a float but 21,2°C
coming from Homekit.
Fixed it by changing the automation line from:
value: "{{ trigger.json.temperature }}"
to:
value: "{{ trigger.json.temperature | replace('°C','') | replace(',', '.') }}"
and now it works like a charm.
Also, Homekit only worked for me using a hostname (e.g. http://hass.local/api/webhook/etc
and not when using an IP address (http://10.0.0.1/api/webhook
) in case anyone is running into this issue.
🙈 Ok I'm an idiot, none of the above is necessary if you set the field in Homekit automation to Number instead of text, which wasn't clear to me.
@FermedePommerieux, What great instructions and help. I haven't actually started yet, but I have already been able to follow all the steps. Tell me, I have 3 Homepods minis, do you have a template that I could use or would you create all 3 Homepods separately using the template? I'm asking because you mentioned that you have activated it for 3 Homepods and have certainly already played through all the pros and cons, whether it makes sense to pack everything into one automation (HA and IOs).
Best regards Seger
If you add:
"state_class" : "measurement"
"device_class" : "temperature"
or
"state_class" : "measurement"
"device_class" : "humidity"
to the JSON requests you can also track statistics on them instead of just history
If you add:
"state_class" : "measurement" "device_class" : "temperature"
or
"state_class" : "measurement" "device_class" : "humidity"
to the JSON requests you can also track statistics on them instead of just history
Please tell me where exactly I need to insert this? in homekit automation or somewhere in the sensor in home assistant?
I found a more correct way to add a history for the sensor.
Instead of the legacy sensor template, you need to use the new sensor template format https://www.home-assistant.io/integrations/template, where you can specify state and device classes.
Below is a piece of code from point 2, which I converted to a new format. Other parts do not need to be changed, they are compatible with the new sensor template format.
template:
- sensor:
- name: "homepodmini_XXXXX_temperature"
unique_id: ff02eebc-b4a5-4761-906c-d4603c70266f
unit_of_measurement: '°C'
device_class: temperature
state_class: measurement
state: "{{states('input_number.homepodmini_XXXXX_temperature')}}"
- name: "homepodmini_XXXXX_humidity"
unique_id: a5e5cf60-7ac1-4147-85d6-fa5e4536c462
unit_of_measurement: '%'
device_class: humidity
state_class: measurement
state: "{{states('input_number.homepodmini_XXXXX_humidity')}}"
@FermedePommerieux: Nice work, thank you!
I don't know why, but I had some problems with the automation stored under bullet point 4. The formatting wasn't right for me at all. I recreated the automation and got the formatting that was right for me.
In case anyone else has these problems, here is the formatting of the automation:
- id: '1703980955663'
alias: update_homekit_sensors
description: Process temperature and humidity from HomePod Mini
trigger:
- platform: webhook
allowed_methods:
- POST
local_only: true
webhook_id: homekit_sensors
id: WebHook
- platform: time_pattern
minutes: /2
id: time
action:
- choose:
- conditions:
- condition: trigger
id:
- WebHook
sequence:
- service: input_number.set_value
data_template:
entity_id: input_number.{{ trigger.json.sensor }}_temperature
value: '{{ trigger.json.temperature }}'
- service: input_number.set_value
data_template:
entity_id: input_number.{{ trigger.json.sensor }}_humidity
value: '{{ trigger.json.humidity }}'
- conditions:
- condition: trigger
id:
- time
sequence:
- service: input_boolean.turn_on
data: {}
target:
entity_id: input_boolean.homekit_sensors_update
- delay:
hours: 0
minutes: 0
seconds: 5
milliseconds: 0
- service: input_boolean.turn_off
data: {}
target:
entity_id: input_boolean.homekit_sensors_update
mode: parallel
max: 10
Nice ! Would you like me to update my initial post ?
@FermedePommerieux, What great instructions and help. I haven't actually started yet, but I have already been able to follow all the steps. Tell me, I have 3 Homepods minis, do you have a template that I could use or would you create all 3 Homepods separately using the template? I'm asking because you mentioned that you have activated it for 3 Homepods and have certainly already played through all the pros and cons, whether it makes sense to pack everything into one automation (HA and IOs).
Best regards Seger
Hello Seger,
Thank you for your question regarding the setup of the automation. To clarify, you will indeed need just one automation to manage all three devices. This single automation is designed to update the sensor corresponding to the specific HomePod Mini that sends a webhook.
It's important to note that any sensor you wish to update via a webhook triggered by each HomePod Mini must be manually configured in Home Assistant (HA). As of now, I have not yet figured out a way to add sensors on the fly in HA, so this setup must be done carefully for each device.
In summary, you do not need to create separate automations for each HomePod Mini. One automation can manage all three, but each HomePod Mini requires specific manual configuration to ensure that the correct sensor is updated based on the received webhook.
I hope this clarifies the situation. Please don't hesitate to reach out if you have more questions or need further assistance with your setup.
Best regards
However, I've noticed an issue with one of my HomePod Minis in cold environments (around 12°C): the temperature readings do not drop below 17.5°C. I suspect this might be related to the operating temperature of the HomePod Minis themselves. Therefore, be cautious when setting up automations that rely on triggering at temperatures lower than 17.5°C.
If you add:
"state_class" : "measurement" "device_class" : "temperature"
or
"state_class" : "measurement" "device_class" : "humidity"
to the JSON requests you can also track statistics on them instead of just history
Please tell me where exactly I need to insert this? in homekit automation or somewhere in the sensor in home assistant?
You do it through webhooks and submitting to specific endpoints for your sensors and HA will create sensors for you on the fly, no need at all to configure anything for it.
For example, for my kitchen homepod:
Get contents of: http://hass.local:8123/api/states/sensor.kitchen_temperature
Values I'm submitting:
"state" : <current numeric value>
"device_class":"temperature"
"state_class": "measurement"
Get contents of http://hass.local:8123/api/states/sensor.kitchen_humidity
Values I'm submitting:
"state" : <current numeric value>
"device_class":"humidity"
"state_class": "measurement"
You will now have two new sensors in HA, namely sensor.kitchen_temperature
and sensor.kitchen_humidity
as soon as the automation is triggered. I use @FermedePommerieux their trick of setting the switch on and off with the timer to trigger the automations.
Note that you can simply change the sensor names, so if you want to have a sensor called sensor.my_sensor
you just change the url you call to http://hass.local:8123/api/states/sensor.my_sensor
Hope that helps! I've got it running for 4 homepods in my house, which means you have to unfortunately call 8 different URLs to get both sensor and humidity but no config on the HA side of things.
Super cool workaround. But the majority of Home Assistant users will probably not be able to find this and learn from this. It would be better if you guys create a new topic in the Community forum at https://community.home-assistant.io/ and discuss there?
Additionally, we can continue monitoring this specific issue (no native support) with GitHub.
Thanks!
@FermedePommerieux yeah sure!
Get contents of:
http://hass.local:8123/api/states/sensor.kitchen_temperature
Values I'm submitting:
Wow, this is a perfect example of KISS: Keep It Stupidly Simple! I absolutely love it!
Super cool workaround. But the majority of Home Assistant users will probably not be able to find this and learn from this. It would be better if you guys create a new topic in the Community forum at https://community.home-assistant.io/ and discuss there?
Responding to the suggestion about creating a new topic on the Home Assistant community forum, I am fully supportive of it. It's indeed a great idea to disseminate this workaround to a broader audience. With your permissions, I plan to initiate a new, simplified version of the how-to guide, utilizing Mensoh's method. I'll submit it here before opening a new topic. Additionally, I would be very grateful for any English-language screenshots of HomeKit automations. These visual aids would be tremendously helpful in enhancing understanding and aiding others in implementing similar setups in our community.
Well, it seems that the /api/states/ method requires authentication. How did you manage that? This might make configuration in HomeKit more challenging.
I'm planning to explore calling localhost/api/states/ in the automation to create sensors on the fly, without needing additional configuration. I'll look into it tomorrow.
Ah this is a fair point, you need to enable the REST API and create an API key, you can read more on how to do that here in the HA documentation.
So this means in your Apple Home automation when you make the Get contents of
request you will need to add an additional Header
to the request:
key: Authorization
text: Bearer <your api key>
then in the Body
you send state
, state_class
and device_class
as mentioned before.
I've found a way to bypass the limitation and eliminate the need for authentication/configuration: a simple Python script that can be called from the automation.
update_homekit_sensor.py:
sensor_name = data.get('sensor_name')
sensor_state = data.get('state')
sensor_attributes = data.get('attributes', {})
hass.states.set(sensor_name, sensor_state, sensor_attributes)
I recognize that this approach represents a decrease in security and poses a potential risk of overloading Home Assistant with a large number of spam sensors, which could lead to problems if misused.
Although I prefer using authentication with HomePod Minis, their setup can be quite tedious. Therefore, this method, albeit less elegant and somewhat 'rougher', seems to be more practical and easier to implement for less experienced users.
Here is the updated automation, which doesn't require any further configuration:
alias: Homekit - Sensor Collection
description: Processes temperature and humidity data from the HomePod Mini
trigger:
- platform: webhook
webhook_id: homekit_sensors
allowed_methods:
- POST
local_only: true
id: WebHook
- platform: time_pattern
minutes: /2
id: time
action:
- choose:
- conditions:
- condition: trigger
id: WebHook
sequence:
- service: python_script.update_homekit_sensor
data:
sensor_name: sensor.{{ trigger.json.sensor }}_humidity
state: "{{ trigger.json.humidity }}"
attributes:
unit_of_measurement: "%"
state_class: humidity
device_class: measurement
- service: python_script.update_homekit_sensor
data:
sensor_name: sensor.{{ trigger.json.sensor }}_temperature
state: "{{ trigger.json.temperature }}"
attributes:
unit_of_measurement: "°C"
state_class: temperature
device_class: measurement
- conditions:
- condition: trigger
id: time
sequence:
- service: input_boolean.turn_on
data: {}
target:
entity_id: input_boolean.homekit_sensors_update
- delay:
hours: 0
minutes: 0
seconds: 5
milliseconds: 0
- service: input_boolean.turn_off
data: {}
target:
entity_id: input_boolean.homekit_sensors_update
mode: parallel
max: 10
I propose offering two ways of configuration: one secure using an API key and one less secure with a Python script. I'm planning to create a blueprint for this.
You can use the following two methods:
Create an input_boolean
Exposed to HomeKit:
input_boolean:
homekit_sensors_update:
name: Collection of HomeKit Sensors
initial: off
Include this input_boolean
in the HomeKit configuration:
homekit:
- name: Your House
port: 56320 # Or another available port
filter:
include_entities:
- input_boolean.homekit_sensors_update
Create a Python Script in the config/python_script
Directory:
update_homekit_sensor.py
:
sensor_name = data.get('sensor_name')
sensor_state = data.get('state')
sensor_attributes = data.get('attributes', {})
hass.states.set(sensor_name, sensor_state, sensor_attributes)
Create an Automation in Home Assistant:
This automation updates/creates sensors based on data received via a webhook and activates the input_boolean
to request an update in HomeKit.
alias: Homekit - Sensor Collection
description: Processes temperature and humidity data from the HomePod Mini
trigger:
- platform: webhook
webhook_id: homekit_sensors
allowed_methods:
- POST
local_only: true
id: WebHook
- platform: time_pattern
minutes: /2
id: time
action:
- choose:
- conditions:
- condition: trigger
id: WebHook
sequence:
- service: python_script.update_homekit_sensor
data:
sensor_name: sensor.{{ trigger.json.sensor }}_humidity
state: "{{ trigger.json.humidity }}"
attributes:
unit_of_measurement: "%"
state_class: humidity
device_class: measurement
- service: python_script.update_homekit_sensor
data:
sensor_name: sensor.{{ trigger.json.sensor }}_temperature
state: "{{ trigger.json.temperature }}"
attributes:
unit_of_measurement: "°C"
state_class: temperature
device_class: measurement
- conditions:
- condition: trigger
id: time
sequence:
- service: input_boolean.turn_on
target:
entity_id: input_boolean.homekit_sensors_update
- delay: '00:00:05'
- service: input_boolean.turn_off
target:
entity_id: input_boolean.homekit_sensors_update
mode: parallel
max: 10
Set Up an Automation in the HomeKit App:
This automation triggers when homekit_sensors_update
is activated. It obtains temperature and humidity values and sends this data to Home Assistant using a Get content action via http://homeassistant:8123/api/webhook/homekit_sensors
using POST with a JSON payload.
JSON format:
{
"sensor": "XXXXX", # Must be text
"temperature": numeric value, # Must be numerical
"humidity": numeric value # Must be numerical
}
This method uses HomeKit as an intermediary to integrate HomePod Mini sensors into Home Assistant.
Create an input_boolean
Exposed to HomeKit:
(Same as in Method A)
Create an Automation in Home Assistant: (Same as in Method A, but with only the time_pattern trigger)
Set Up an Automation in the HomeKit App:
This automation triggers when homekit_sensors_update
is activated. It obtains temperature and humidity values and sends this data to Home Assistant via http://homeassistant:8123/api/states/your_sensor_humidity
and http://homeassistant:8123/api/states/your_sensor_temperature
using POST with a JSON payload.
Before this step, enable the REST API and create an API key in Home Assistant.
In your Apple Home automation, add an additional header in the two Get contents of the request:
JSON format for temperature:
{
"state": current_homepodmini_temperature, # Must be numerical
"device_class": "measurement",
"state_class": "temperature"
}
JSON format for humidity:
{
"state": current_homepodmini_humidity, # Must be numerical
"device_class": "measurement",
"state_class": "humidity"
}
Here is the link to the community guide topic: https://community.home-assistant.io/t/how-to-integrate-homepod-mini-sensors-into-home-assistant-when-direct-integration-isnt-possible/665074
I found a more correct way to add a history for the sensor.
Instead of the legacy sensor template, you need to use the new sensor template format https://www.home-assistant.io/integrations/template, where you can specify state and device classes.
Below is a piece of code from point 2, which I converted to a new format. Other parts do not need to be changed, they are compatible with the new sensor template format.
template: - sensor: - name: "homepodmini_XXXXX_temperature" unique_id: ff02eebc-b4a5-4761-906c-d4603c70266f unit_of_measurement: '°C' device_class: temperature state_class: measurement state: "{{states('input_number.homepodmini_XXXXX_temperature')}}" - name: "homepodmini_XXXXX_humidity" unique_id: a5e5cf60-7ac1-4147-85d6-fa5e4536c462 unit_of_measurement: '%' device_class: humidity state_class: measurement state: "{{states('input_number.homepodmini_XXXXX_humidity')}}"
Newb Q- is it relevant the entity name has XXXX in homepodmini_XXXXX_humidity?
I see in other parts of the code _temperature
is appended.
Can I call these entities homepod_gen2_1of2
instead of homepodmini_XXXXX
?
The choice of the entity's name is entirely up to your personal preferences and how you want to organize and identify your devices. The "XXXX" in homepodmini_XXXXX_humidity is a unique identifier for a specific device. It helps to distinguish this entity from other similar entities you might have in your system. However, there is no technical constraint that prevents you from renaming this entity. Additionally, using suffixes like _temperature helps to distinguish between different types of sensors, such as a humidity sensor and a temperature sensor, making it clearer which is which.
@mensoh, However, the values must be summarised as a dictionary under the key attributes
.
Then they are listed, at least for me. Or am I doing something wrong ;-)?
Is it possible to give a unique ID so that the icon can be edited? I don't think so, at least I couldn't manage it. You can enter something via attributes, but the UI doesn't care (maybe because it's a read-only sensor?). The icon is displayed correctly for temperature, but unfortunately not for humidity. Can you perhaps help again? Thank you
JSON format for temperature:
"device_class": "measurement",
"state_class": "temperature"
JSON format for humidity:
"device_class": "measurement",
"state_class": "humidity"
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.
Not yet fixed
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.
Keep
Keep
Keep
Keep
Hello There
While fixing some of my config I figured that I could also check some error logs regarding this solution
The error appeared whenever the sensor was unavailable or in unknown state and the message was:
ValueError: Sensor sensor.homepodmini_humidity has device class 'humidity', state class 'None' unit '%' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: states('sensor.homepodmini_humidity')
I did add the following so it will resolve the error and also stop my Temperature and Humidity graphs from braking when a string character appeared in the history
- sensor:
- name: "Homepodmini Temperature"
unique_id: homepodmini_temperature
unit_of_measurement: "°C"
device_class: temperature
icon: mdi:thermometer
state: >
{% if is_state('sensor.homepodmini_temperature', ['unknown', 'unavailable']) -%}
{{ 0.0 }}
{%- else -%}
"{{ states('sensor.homepodmini_temperature')}}"
{%- endif %}
Now the only issue I see is the following, is that normal for this implementation?
`2024-11-16 23:32:03.470 WARNING (MainThread) [homeassistant.components.template.template_entity] Template loop detected while processing event: <Event state_changed[L]: entity_id=sensor.homepodmini_humidity, old_state=<state sensor.homepodmini_humidity=0.0; unit_of_measurement=%, device_class=humidity, icon=mdi:water-percent, friendly_name=Homepodmini Humidity @ 2024-11-16T23:31:20.786363+02:00>, new_state=<state sensor.homepodmini_humidity=0 @ 2024-11-16T23:32:03.463732+02:00>>, skipping template render for Template[{% if is_state('sensor.homepodmini_humidity', ['unknown', 'unavailable']) -%} {{ 0.0 }} {%- else -%} "{{ states('sensor.homepodmini_humidity')}}" {%- endif %}]`
Thanks @FermedePommerieux, this method works quite well!
However, the humidity value only gets correctly populated when I manually test the automation from the HomeKit app, otherwise it registers as 0.0%.
edit: I got it working, for some reason the Home automation was using the "Current state" variable instead of "current relative humidity". Weird that it worked when manually triggering...
This issue was driving me crazy so I went down the rabbit hole and figured out there's a bug in HomeKit where running on AppleTV compared to running from an iPhone or Mac where humidity sensors are 0 or 1 instead of the actual value.
So solve this issue you have to switch between name and current relative humidity a few times until the correct value gets returned. Make sure to do the testing via the actual endpoint and not via the "Test Automation" button on your phone or laptop as the automation will be tested locally instead of where HA will run it, which is AppleTV.
Hello There
While fixing some of my config I figured that I could also check some error logs regarding this solution
The error appeared whenever the sensor was unavailable or in unknown state and the message was:
ValueError: Sensor sensor.homepodmini_humidity has device class 'humidity', state class 'None' unit '%' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: states('sensor.homepodmini_humidity')
I did add the following so it will resolve the error and also stop my Temperature and Humidity graphs from braking when a string character appeared in the history
- sensor: - name: "Homepodmini Temperature" unique_id: homepodmini_temperature unit_of_measurement: "°C" device_class: temperature icon: mdi:thermometer state: > {% if is_state('sensor.homepodmini_temperature', ['unknown', 'unavailable']) -%} {{ 0.0 }} {%- else -%} "{{ states('sensor.homepodmini_temperature')}}" {%- endif %}
Now the only issue I see is the following, is that normal for this implementation?
`2024-11-16 23:32:03.470 WARNING (MainThread) [homeassistant.components.template.template_entity] Template loop detected while processing event: <Event state_changed[L]: entity_id=sensor.homepodmini_humidity, old_state=<state sensor.homepodmini_humidity=0.0; unit_of_measurement=%, device_class=humidity, icon=mdi:water-percent, friendly_name=Homepodmini Humidity @ 2024-11-16T23:31:20.786363+02:00>, new_state=<state sensor.homepodmini_humidity=0 @ 2024-11-16T23:32:03.463732+02:00>>, skipping template render for Template[{% if is_state('sensor.homepodmini_humidity', ['unknown', 'unavailable']) -%} {{ 0.0 }} {%- else -%} "{{ states('sensor.homepodmini_humidity')}}" {%- endif %}]`
Hi @DrRikons , I did not see the error you were seeing, however I tried your changes to my template sensors. This resulted in breaking the implementation on my side.
ValueError: Sensor sensor.homepodmini_buero_temperature has device class 'temperature', state class 'measurement' unit '°C' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: '"21.0"' (<class 'str'>)
Therefore I reverted back.
Hello There While fixing some of my config I figured that I could also check some error logs regarding this solution The error appeared whenever the sensor was unavailable or in unknown state and the message was:
ValueError: Sensor sensor.homepodmini_humidity has device class 'humidity', state class 'None' unit '%' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: states('sensor.homepodmini_humidity')
I did add the following so it will resolve the error and also stop my Temperature and Humidity graphs from braking when a string character appeared in the history- sensor: - name: "Homepodmini Temperature" unique_id: homepodmini_temperature unit_of_measurement: "°C" device_class: temperature icon: mdi:thermometer state: > {% if is_state('sensor.homepodmini_temperature', ['unknown', 'unavailable']) -%} {{ 0.0 }} {%- else -%} "{{ states('sensor.homepodmini_temperature')}}" {%- endif %}
Now the only issue I see is the following, is that normal for this implementation?
`2024-11-16 23:32:03.470 WARNING (MainThread) [homeassistant.components.template.template_entity] Template loop detected while processing event: <Event state_changed[L]: entity_id=sensor.homepodmini_humidity, old_state=<state sensor.homepodmini_humidity=0.0; unit_of_measurement=%, device_class=humidity, icon=mdi:water-percent, friendly_name=Homepodmini Humidity @ 2024-11-16T23:31:20.786363+02:00>, new_state=<state sensor.homepodmini_humidity=0 @ 2024-11-16T23:32:03.463732+02:00>>, skipping template render for Template[{% if is_state('sensor.homepodmini_humidity', ['unknown', 'unavailable']) -%} {{ 0.0 }} {%- else -%} "{{ states('sensor.homepodmini_humidity')}}" {%- endif %}]`
Hi @DrRikons , I did not see the error you were seeing, however I tried your changes to my template sensors. This resulted in breaking the implementation on my side.
ValueError: Sensor sensor.homepodmini_buero_temperature has device class 'temperature', state class 'measurement' unit '°C' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: '"21.0"' (<class 'str'>)
Therefore I reverted back.
Hi @housemaister ,
Update on the topic: Turns out I still got the same errors even after the implementation I mention above.
Finally I decided to comment out both humidity and temperature sensor in configuration.yaml
and most of these errors were gone.
The sensors will still work without having a template, downside is that I still get a "no state class" or a "non-numeric value" error but only whenever the homepod sensors are unavailable (sensor state = "unknown" or "unavailable"
I still retain them though in the homekit config :
################################## Homepod Temp #######################################
# - sensor:
# - name: "Homepodmini Temperature"
# unique_id: homepodmini_temperature
# unit_of_measurement: "°C"
# device_class: temperature
# state_class: measurement
# icon: mdi:thermometer
# state: "{{ states('sensor.homepodmini_temperature') }}"
# - sensor:
# - name: "Homepodmini Humidity"
# unique_id: homepodmini_humidity
# unit_of_measurement: "%"
# device_class: humidity
# state_class: measurement
# state: "{{ states('sensor.homepodmini_humidity') }}"
input_boolean:
homepodmini_sensors_collection:
name: Collection of HomePod Sensors
initial: off
homekit:
- name: Homepod Mini Sensors
unique_id: Homepod_bedroom
mode: accessory
port: 56320 # Or another available port
filter:
include_entities:
- input_boolean.homepodmini_sensors_collection
- sensor.homepodmini_temperature
- sensor.homepodmini_humidity
To configure class, icons etc for the sensors this way you have to change the apple homekit shortcut and define an attributes array of objects to add there sensor class, unit etc
The problem
HomePod mini includes a temperature and humidity sensor, which are exposed to Apple’s home app.
However, HA’s Apple TV integration does not detect these sensors to make them available as an entity.
What version of Home Assistant Core has the issue?
core-2023.11.0
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant OS
Integration causing the issue
Apple TV
Link to integration documentation on our website
https://www.home-assistant.io/integrations/apple_tv
Diagnostics information
No response
Example YAML snippet
No response
Anything in the logs that might be useful for us?
No response
Additional information
No response