I have seen this request a few times in the forums. Putting a post together so I can link to it rather than find and paste the text each time.
This example uses a device_tracker entity which normally displays home or not_home for the state. This makes sense for a person, but for a computer or device online or offline may make more sense. Here is how to make that change. Its a bit of a round about way of doing it and not the most efficient option, but it works and is the only option I am aware of right now.
To do this we will use a template sensor:
To change my device_tracker.000c0e0f00ed from home/not_home to online/offline the code looks like like the following:
sensor:
- platform: template
sensors:
desktop:
value_template: '{% if is_state("device_tracker.000c0e0f00ed", "home") %}Online{% else %}Offline{% endif %}'
friendly_name: 'Desktop'
Note: This code will only work with a entity that has two states. In the example above if device_tracker.000c0e0f00ed had a state of āWorkā the state of our new sensor would be āofflineā
Also, keep the sensor name (desktop in this example) lower case. I have seen issues when capital options are used.
Here is the same setup, using generic examples:
sensor:
- platform: template
sensors:
sensor_name:
value_template: '{% if is_state("entity_ID", "State 1") %}New State 1{% else %}New State 2{% endif %}'
friendly_name: 'Name'
Now in my example I have a new entity after a restart of āsensor.desktopā. I would add this to my front end and remove ādevice_tracker.000c0e0f00edā. The result is as shown below.