Input_boolean read-only on the GUI

Hello,

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?

Thanks

I would start here, specifically the “Switch As Sensor” section.

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.

I don’t think there is a way around creating a template sensor based on the input_boolean if you really want to keep it a read-only in the UI.

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.

A Sensor looks good on the Dashboard but how can i Set the value from an automation then?

Many Thanks and Best Regards

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

Guess the same like this applies to a binary_sensor :stuck_out_tongue:

Instead of an automation with a Input Datetime, create a Trigger-based Template Sensor and then the resulting value will be read-only.

BTW, does your binary_sensor actually have an attribute named contact?

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.

An entity displayed in an Entities card can be made ‘read-only’ in the UI by setting the value of type to simple-entity.

A Trigger-based Template Sensor can be made writable via an automation.

1 Like