I made a template sensor to display the state of my gate, using a current sensor on the motor’s wires I can detect if it’s moving or not, and combining it with the open/close sensor I can have three states : closed, moving, opened.
Here is the template to create the sensor and its icon:
Both in the frontend and in the android auto screen, the sensor icon is shown as black/white whatever the state of the sensor. How to make it display as default “active state color” when opened or moving like the alarm or window icons visible in the AA screens below and only keep inactive “black/grey/white” color when closed? So that I can get a quick glance of the gate’s state when driving?
In the HA frontend I’m using the custom-card mod to switch color between grey/white when closed, yellow when moving and red when opened. But I can’t find a way to set the color to “active” for the entity when its state is not “closed”.
Easy, it’s a template sensor, there should be a state color template where you can compare state with some thresholds or discrete values and set colors accordingly.
But it’s not possible in Android Auto or WearOS interfaces.
Using a cover is not a good option, first I have only three states, there is no distinction between opening and closing, it’s merged as “moving”. Second, I don’t have multiple commands, I only have one button, one press makes the gate move one way, second press makes it stop, and third press makes it move the other way. I have no possibility to know the gate’s position except when its closed.
The way the templates are managed is frustrating, it’s really powerful, but it still lacks the capability to set different color for entity’s states. Using the theme is not an option, as it’s not applied in AA or WearOS, and I only want to change colors for one entity.
A simple option to declare “this state is inactive and the others are active” would allow to at least use the standard state color.
Most likely because these systems don’t use WebView, and CSS styles will certainly be more limited compared to browser based frontend…
You can try creating a binary_sensor with a device_class; after that, it will definitely work correctly.
device_class device_class (Optional, default: None)
Sets the class of the device, changing the device state and icon that is displayed on the UI (see below). It does not set the unit_of_measurement.
Have you tried custom:button-card ? Don’t know if it works in AA but it works in the frontend.
Edit - oops, I see you already use this card. What about wrapping a button-card in a custom:config-template-card
I finally succeed in building a cover, and using an automation to store the last know state of the gate while not moving (open or closed) I could also estimate if the gate is closing or opening while moving (I just need to avoid pressing the remote command’s button twice too fast, otherwise the current sensor won’t detect that the motor stopped and restarted in the opposite way).
The “state” template:
{% if is_state("binary_sensor.fgbs222_portail_intrusion", "on") %}
{% if is_state("binary_sensor.portail_en_mouvement", "on") %}
{% if is_state("input_text.portail_dernier_etat_connu", "open") %}
closing
{% else %}
opening
{% endif %}
{% else %}
open
{% endif%}
{% else%}
closed
{% endif %}
Ok, didn’t find a way to do without ; but then how to discriminate if the gate is opening or closing when using the Somfy remote commands or video doorbell’s unlock button ?
My method allows HA to keep in sync even if someone uses the “non-HA managed” buttons to do for example with an open gate: close, stop before it’s closed then re-open.
There is still an issue when using the “cover” method in Android Auto app: when the gate is opening or closing the icon of the entity becomes a turning circle and I can’t click on it anymore; hence I can’t stop the gate and have to wait for it to be fully open or close.