-
Please use a proper formatting for a code - triple “`”, without “>” prefixes.
-
As for “Connected”:
Assume that you have already defined an appropriate “device_class” for this sensor (here - “connectivity”).
Cards like “history-graph”, “entities” (as well as more-info popup) show a translated “nice” labels like “Connected / Disconnected”.
But in templates you will still get “on/off”:
But if you need to get these “Connected / Disconnected” labels - currently you will have to use this extension:
Github repo
Community thread
which gives you this:
Hope one day this functionality will become a part of HA core (check here).

