Changing the States displayed on the frontend of a entity

Great minds think alike, eh? This was part of my tutorial on the SNMP project.

Here’s the thing I don’t understand though; in cases where the sensor class is already defined, for example a binary_sensor for doors/windows, why is this necessary? If the sensor class is already defined as ‘opening’, shouldn’t the values be ‘open’ and ‘closed’ instead of ‘on’ and ‘off’.

Or maybe I’m missing the point of sensor classes?

That may be where I originally saw this code, so credit goes to you on this, I certainly didn’t come up with this, just wanted to post it somewhere for easy reference.

Not sure, haven’t looked into sensor classes yet.

Bah! I probably got it from someone else too. And it’s a good idea to document it. I was commenting more on the use case; we both did it to monitor our local devices the same way!

Here’s the page on sensor classes; I’d be interested in your take after you read it (very quick read) and to see if I’m missing the point.

I certainly don’t see a use other than what you specified. However, you think each example would have the two options for the state specified afterwards. I think I used this in my motion sensor and specified motion but it still is on/off.

I’m going to do a little more research and see what I can come up with, but it seems to me that if HA recognizes a binary_sensor is an “opening” class sensor, it should automatically display the on/off values as open/close. Thanks for looking at it; I just wanted to make sure I wasn’t reading something into it that wasn’t there.

Sorry to “hijack” this conversation but I’m trying to figure out how to how to do this but with a “fake” device_tracker or a template sensor as you’ve mentioned above… what I’d like to see in the front-end though is an entity picture with “home” or “away” status in the orange bar:

With a template sensor method as mentioned above works very well but when it’s not in a group and displayed at the top of HomeAssistant, you do not get the status in the “orange” bar… which is what I’m trying to achieve.

The reason I mention a “fake” device_tracker is because I’m using multiple methods per person to track their whereabouts:

When any of these change state it updates an Input_boolean (e.g. input_boolean.mike_home) which in turn triggers my Home and Away scripts (light on/off, switches on/off, nest home/away, alarm system on/off etc)

- alias: 'Mike Home'
  condition:
    condition: state
    entity_id: input_boolean.mike_home
    state: 'off'
  trigger:
    - platform: state
      entity_id: device_tracker.pi_mikesiphone
      state: 'home' 
    - platform: state
      entity_id: sensor.rfid
      state: '__REDACTED_ (RFID TAG NUMBER)'_ 
    - platform: state
      entity_id: device_tracker.mikes_iphone
      state: 'home' 
    - platform: state
      entity_id: sensor.mikes_keys
      state: 'happy-bubbles-ble' 
  action:
    - service: homeassistant.turn_on
      entity_id: input_boolean.mike_home
    
- alias: 'Mike Away'
  condition:
    condition: state
    entity_id: input_boolean.mike_home
    state: 'on'
  trigger:
    - platform: state
      entity_id: device_tracker.pi_mikesiphone
      state: 'not_home'  
    - platform: state
      entity_id: device_tracker.mikes_iphone
      state: 'not_home'
    - platform: state
      entity_id: sensor.mikes_keys
      state: 'away'
  action:
    - service: homeassistant.turn_off
      entity_id: input_boolean.mike_home

To summarise, I’m trying to get this:

To change from “home” and “away” based on the input booleans above… purely for aesthetics, and it could even replace the input booleans!

Hoping someone can help!

Thanks :slight_smile:

Did you get this to work @badgerhome ?

Stupid question from me … I was able to implement what silvrr described, but it seems as if you have to configure “track: true” in known_devices.yaml, right? I’ve set it to “track: false” and the status was not set to online/offline using the template sensor from above.
The problem setting tracking to true is that it “breaks” the real home / not_home story, doesn’t it? Lets assume that I want to see if my server or printer is online … they might be running while I (IOW my mobile phone) am not at home so that the presence state will never switch to “not_home” while my server/printer is still online?
Or am I missing something?

Although my last question was not answered yet this might be the perfect solution: https://home-assistant.io/components/binary_sensor.ping/ Have not tried it yet because it was just released and I have not yet upgraded HA.

@badgerhome This is exactly what I am trying to achieve! Did you ever find a solution? Does anyone have any ideas?

Thanks,

Tom

1 Like

@eBoon unfortunately I did not find a solution. I’m still using the multiple input Booleans

Have looked at the Custom UI: Badges in state cards?

2 Likes

Thank you this is so helpful for me

@silvrr

When i want muliple sensors, should it be:

sensor:
  - platform: template
    sensors:
      desktop:
        value_template: '{% if is_state("device_tracker.000c0e0f00ed", "home") %}Online{% else %}Offline{% endif %}'
        friendly_name: 'Desktop' 
    sensors:
      laptop:
        value_template: '{% if is_state("device_tracker.000c0e0f00ed", "home") %}Online{% else %}Offline{% endif %}'
        friendly_name: 'laptop'

or

sensor:
  - platform: template
    sensors:
      desktop:
        value_template: '{% if is_state("device_tracker.000c0e0f00ed", "home") %}Online{% else %}Offline{% endif %}'
        friendly_name: 'Desktop' 
      laptop:
        value_template: '{% if is_state("device_tracker.000c0e0f00ed", "home") %}Online{% else %}Offline{% endif %}'
        friendly_name: 'laptop'

Option #2. You are making a list of the sensors. Im pretty sure the first option would error out.

Since you are having issues with nmap you may want to look at the ping binary sensor.

It reports connected/disconnected on the front end. Rather than create a device tracker and convert it to a sensor that ping sensor may be easier.

Also a bit less traffic on your network. Nmap is by no means a lot of bandwith but it scans 100 ports each scan and you have it set for 4 times a minute so 400 ports being scanned multiplied by the number of hosts you select each minute.

Edit: keep in mind some devices (nest thermostat, amazon echo for example) don’t respond to ping requests. I have found these don’t seem to work with the nmap component either.

Thanks. Option 2 works.

Ping was even worse… It didn’t report them not_home. Ill change the 4 min to longer when im done testing. No need for 4 times a minute.

Maby my windows pc’s are setup wrong, i dont know wats wrong.

Hey @badgerhome how did you set up your rfid ? Have you got the esp8266 arduino libraries and code? I have a pn532 and cannot set it up with my esp8266.

Can you please help?

Thanks.

This is how I set mine up: DIY Poor man's Alarm Control Panel

1 Like

Hi,
I have been doing the template change from home to online for a while now, but it is getting a bit boring.
Has anybody found a way to automate this?
Generic Template and a big loop?
MQTT sensor similar to the battery alert?
Maybe Lovelace filter cards?

OK, I have tried the MQTT discovery option.
And it looks like it would be possible to generate a sensor or binary_sensor for each device_tracker entity and set the STATE to Online / Offline or whatever you prefer.

But then I found that I still want to customize my friendly name and the icon for online and offline and maybe a few other things. Overall it won’t really make the manual process go away …

It was a nice exercise and I learned some things about the MQTT and discovery, but I will go back to the manual process.