Is it possible to have an entity identical to the following input_boolean:
> foo:
> name: "foo"
> initial: off
but which is READ ONLY on the GUI (and is set by some logic of hass)?
I read somewhere that it can be obtained with a binary_sensor, but what should be the syntax?
From what I see, in the way you suggested I would have to wrap an input_boolean. I don’t want to add this additional layer, and I wonder if is there a way to avoid that
Well, to my understanding everything in HA that starts with input_ is user-changeable. Therefore, as controls you should use input_xxx.
On the other hands, sensors exist to display states of another entities and therefore are read-only by its nature.
Yes, they don’t look like input_xxx entities, but that’ the way it works in HA.
As I mentioned above, all input_xxx entities are user-changeable (i.e NOT read-only) by design and therefore (imho) cannot be made read-only unless you hack into the code.
My suggestion is to use template binary sensor instead as it reflects the entity’s read-only (display-only) status.
If you are wanting to set the time value based on an automation then ironically I just had fun creating one. Shows up as editable in the UI though, which I think I can live with. Whenever the contact sensor on my mailbox is opened the input_datetime value gets updated with just the time as I picked only Time when creating the input_datetime from Helpers. When in the dashboard ‘c’ is a good shortcut to know to navigate through the UI. Just a quick way to jump around and never knew about it until recently. More info about the input_datetime helper value can be found here
alias: Mail Last Opened
description: When the mailbox was last opened
trigger:
- platform: state
entity_id:
- binary_sensor.mail_sensor_contact
attribute: contact
from: "off"
to: "on"
condition: []
action:
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.mail_sensor_contact
data:
time: "{{ now().strftime('%H:%M:%S') }}"
mode: single
It shouldn’t be too hard to have a read-only flag to set on the lovelace component. I.e. have a read-only configuration variable.
This way, we don’t have to create read-only entities, as they have to be writable at some point, at least by an automation, but they can be shown read-only in GUI.
Right now, all I can think of is using template sensors to display a read-only value based on an input, so that’s my work-around for now.