State badge
Home Assistant's entity badge has one icon and one color. The state badge has rules: when the temperature is above 25, red, with a warning icon. When the door is open, a different icon, and the word "Open". The first rule that holds sets the look. When none holds, it looks like Home Assistant's own entity badge.
No templates, no YAML needed. You pick it all in the editor.
It needs Spook on your dashboards switched on.
Rules
A rule is a condition on the state of the entity, and how the badge looks while it holds.
The condition, any of:
- State is: the entity is in one of these states. Pick Unavailable and Unknown both, for a rule that holds when the entity is gone.
- State is not: the entity is in none of these states.
- Above: the state is a number above this one.
- Below: the state is a number below this one.
Above and Below together: between the two. Everything you fill in must hold for the rule to hold. A rule with no condition never holds.
A state that is not a number, like Unavailable or Unknown, is never above or below anything. A rule on a number does not hold for it, and nothing breaks.
States go as Home Assistant stores them, not as it shows them: a door that shows Open is on, a closed one off. A rule offers on, off, Unavailable and Unknown to pick, and takes any other state typed in, like home or heat. It does not know which entity the badge is for, so it cannot list the states of that entity. Settings > Tools > States shows them.
The look, any of:
- Icon: the icon while the rule holds.
- Color: the color while the rule holds. It shows also when the entity is off: that the rule holds is the point. A color from the list follows your theme.
- Text: shown in place of the state while the rule holds, like "Open" or "Too warm".
What a rule leaves empty stays as it is without the rule.
The rules go from top to bottom, and the first one that holds wins. Put the strictest first: "above 30" before "above 25", or "above 25" always wins.
Adding it to a dashboard
- Open the dashboard, and edit it.
- Select Add badge, and search for State (Spook).
- Pick the entity.
- Under Rules, select Add, fill in the rule, and select Add again. Once per rule. Drag them to change their order.
- Select Save.
Options
Besides the rules, the state badge has the options of Home Assistant's own entity badge, with the same names, and it does the same with them:
| Option | What it does |
|---|---|
| Entity | The entity the badge shows, and the rules look at. |
| Name | The name, when it is shown. The entity's own if left empty. |
| Icon | The icon when no rule holds. The entity's own if left empty. |
| Color | The color when no rule holds, while the entity is on. The color of its state if left at State. |
| Show name | The name above the state, or in its place when the state is not shown. |
| Show state | The state, or the text of the rule that holds. |
| Show icon | The icon. |
| Tap behavior | What selecting the badge does. More info if left empty, like Home Assistant's own badge. Nothing makes it a badge you cannot select. |
There is no hold and no double tap action.
In YAML
A door, with an icon for open and one for closed:
type: custom:spook-state-badge
entity: binary_sensor.front_door
rules:
- state: "on"
icon: mdi:door-open
color: red
text: Open
- state: "off"
icon: mdi:door-closed-lock
color: green
A temperature with two thresholds, and an icon for when the sensor is gone:
type: custom:spook-state-badge
entity: sensor.living_room_temperature
show_name: true
rules:
- above: 25
icon: mdi:thermometer-alert
color: red
- below: 18
icon: mdi:snowflake-thermometer
color: blue
- state: [unavailable, unknown]
icon: mdi:thermometer-off
Put on and off in quotes. Without them, YAML reads them as true and false.
A rule:
| Key | Values |
|---|---|
state | A state, or a list of states |
state_not | A state, or a list of states |
above | A number |
below | A number |
icon | An icon, like mdi:door-open |
color | A color of your theme, like red or primary, or any CSS color |
text | Any text |
The badge:
| Key | Values | Default |
|---|---|---|
entity | An entity ID | Required |
rules | A list of rules | No rules |
name | Any text | The entity's name |
icon | An icon | The entity's icon |
color | A color, as in a rule | The state's color |
show_name | true or false | false |
show_state | true or false | true |
show_icon | true or false | true |
tap_action | An action, as on any card | More info |
Showing it only when something is off
A badge that is only there when the door is open, or the room is too warm? That is not an option of the state badge, because every badge has it already: the Visibility tab of the badge editor. Give it the same condition as your rule, and the badge only shows up while it holds.
More than one? Put them together under an Or condition. Side by side, every condition on that tab must hold at once, and "above 25" and "below 18" never do.
Held automations card and badge
A card with the automations Spook snoozed or turned on for a while, and when they come back, with a button to end it early. And a badge with how many there are. Both gone when nothing is on hold.
Batteries card and badge
A card with every battery that needs attention, lowest first, at your own threshold. Phones, what charges and what carries Spook's label left out. And a badge with how many there are. Both gone when every battery is fine.
