Need some help with templating!

Hey all,

I’ve been wrestling with my HA setup for around a year now and have also been on here reading stuff which has been a massive help but I’m now trying to tackle a bit of templating and I need to post and request help with a couple things!

  1. I’ve created media players to act as a kinda input select bridge in HomeKit… Some of which are people’s states (mostly just to use as conditions in automations). So I was going to have sources/options of home, away, awake, asleep but decided I could just have awake & asleep and then have it turn off when not home. I don’t seem to be able to set person as the state. I tried writing a messy template but it just didn’t work at all.

Tl;dr- How do I write a state_template so my universal media player is on when person.a is home and off if they’re not?

  1. I’ve just set up the news Tuya which is fantastic compared to my old setup using Alexa to send commands to dummy switches which then altered sensors BUT they come with battery binary sensors that just show normal and low (I assume). However, these can’t be used as a linked_battery_sensor when putting them into HomeKit.

Tl;dr- How can I make a template sensor that can show numbers/percentages based on binary sensor? I don’t care what the numbers are but they might as well be 1 and 100.

Thanks in advance for any help anyone can offer!

Seems like it would be much easier to create a simple automation or two. Use the state of person A to trigger a device to toggle on/off.

Not sure what you are trying to achieve here. Are you wanting to take one of the attributes from your sensor and create an entirely new entity?

For an example, I use the AccuWeather integration. Normally the weather state is something like “Sunny” or “Cloudy” when all I want is the actual temperature. So I took the temperature attribute from that entity and created an all new sensor like it shows below.

sensor:
  - platform: template
    sensors:
      outside_temperature:
        friendly_name: Outside Temperature
        unit_of_measurement: 'degrees'
        value_template: "{{ state_attr('weather.accuweather', 'temperature') }}"

So if your sensor has attributes for the battery, you could use the above example to make a new template sensor that only outputs your battery percentage.

That’s a good idea with the first one. I don’t really want the switches to do anything though. Would binary sensors based on the source work instead?

HomeKit doesn’t recognise binary sensors as attached battery sensors and that seems to be all that the entity has:

So I’d like to create a sensor that shows a number/percentage that I can then attach to it. Then the home app will show a warning when the entity changes to from “Normal” to “Low” (because the binary will have changed from 100 to 1). Does that make any more sense?