Smoke sensor with statuses

I’m writing an integration for bolid security system. It have a two wire bus for signal and power and many sensors. There is an ordinary sensors (temperature / humidity / current / voltage and other) and security. Security sensors is not a binary - they have a state integer field.

Smoke sensor can have many states: test, fire, dusted, lost, service required, bad power, armed/disarmed and many others. Door sensors have same configuration so I can’t just use binary_sensor platform. Is there platform more suitable for such hardware ?

The standard sensor should do the job.

But you will most likely not be able to use the predefined classes for you smoke detector.
If you’re writing an integration, I’d recomand to populate 2 sensors, a generic one for the “real” status and a binary one with device_class: smoke. That last one being fire = on, other = off.

The same applies to your door sensor: a generic sensor for detail but a binary sensor with device_class: door

Sounds reasonable. Is there any way to make a generic sensor with predefined states to convert numeric state into text string native ? Or this can be done by interface integrations ?

You can use the template of HA to do so:

template:
  - sensor:
    - name: Smoke detector status
      state: >
        {% set human_status = ['test', 'fire', 'dusted', 'lost', 'service required', 'bad power', 'armed', 'disarmed' ] %}
        {{ human_status[integer field] }}       

Please note that array starts at 0
So, if your integer is 0, this will return ‘test’ and so on.
If the integer field doesn’t start at 0, you can add a fake value as first one like ['', 'test', ... therefore 1 will be test.
If the integer field is not consecutive values, then prefer a if elif structure:

      state: >
        {% if integer field == 42 %}
          test
        {% elif integer field = 17 %}
          fire
        {% else %}
          unknown
        {% endif %}

EDIT Or use a dictionnary

      state: >
        {% set human_status = ['17':'test', '42':'fire', '173':'dusted', ... ] %}
        {{ human_status[integer field] if integer field in human_status.keys() else 'unknown' }}
1 Like

Thank you! I found a SensorDeviceClass.ENUM type and think with templates it will be great solution.