esphome / feature-requests

ESPHome Feature Request Tracker
https://esphome.io/
415 stars 26 forks source link

Would be possible to add the Senseair Sunrise CO2 sensor? #2870

Open Jpm100P2 opened 1 month ago

Jpm100P2 commented 1 month ago

Dear community, is it possible to add the support for Senseair Sunrise CO2 sensor?

The company changed the protocol so the current existing S8 component can not be used.

Thanks.

Please describe your use case for this integration and alternatives you've tried:

Additional context

For those that doesn't know it it's a very accurate CO2 sensor that is normally installed in professional CO2 meters.

Sizurka commented 1 day ago

While it's not that elegant, these sensors speak standard Modbus when they're in UART mode (COMSEL high or floating). So you can interface with them using ESPHome's generic Modbus support. Below is part of the configuration I use for the one I have. If you just want CO2 out of it with all defaults, you can cut off everything below the CO2 sensor, likewise there's lots I didn't implement; check Senseair's Modbus documentation.

uart:
  baud_rate: 9600
  tx_pin: GPIO04
  rx_pin: GPIO03

modbus_controller:
  - id: sunrise_sensor
    address: 0x68

sensor:
  - platform: modbus_controller
    name: "CO2 Concentration"
    device_class: carbon_dioxide
    state_class: measurement
    unit_of_measurement: ppm
    accuracy_decimals: 0
    modbus_controller_id: sunrise_sensor
    register_type: read
    address: 0x03
    value_type: S_WORD
#  - platform: modbus_controller
#    id: co2_sensor_temperature
#    device_class: temperature
#    state_class: measurement
#    unit_of_measurement: "°C"
#    accuracy_decimals: 1
#    modbus_controller_id: sunrise_sensor
#    register_type: read
#    address: 0x04
#    value_type: S_WORD
#    filters:
#      - multiply: 0.01

number:
  - platform: modbus_controller
    id: co2_sensor_pressure
    modbus_controller_id: sunrise_sensor
    address: 0x2E
    register_type: holding
    use_write_multiple: true
    value_type: S_WORD
    min_value: 300
    max_value: 1300
    multiply: 10

  - platform: modbus_controller
    name: "Ambient CO2 Baseline"
    device_class: carbon_dioxide
    entity_category: config
    mode: box
    unit_of_measurement: ppm
    modbus_controller_id: sunrise_sensor
    address: 0x0F
    register_type: holding
    use_write_multiple: true
    value_type: S_WORD
    min_value: 400
    max_value: 16000

switch:
  - platform: modbus_controller
    name: "CO2 Pressure Compensation"
    entity_category: config
    disabled_by_default: true
    modbus_controller_id: sunrise_sensor
    register_type: holding
    use_write_multiple: true
    address: 0x12
    bitmask: 0x10
    inverted: true
    restore_mode: DISABLED

binary_sensor:
  - platform: modbus_controller
#    name: "CO2 Sensor Fatal Error"
    id: sunrise_fatal_error
    entity_category: diagnostic
    modbus_controller_id: sunrise_sensor
    register_type: read
    address: 0x00
    bitmask: 0x0001
    on_press:
      then:
        lambda: 'id(sunrise_fatal_error)->status_set_error("Sunrise fatal error");'
    on_release:
      then:
        lambda: 'id(sunrise_fatal_error)->status_clear_error();'
  - platform: modbus_controller
#    name: "CO2 Sensor Communication Error"
    id: sunrise_communicator_error
    entity_category: diagnostic
    modbus_controller_id: sunrise_sensor
    register_type: read
    address: 0x00
    bitmask: 0x0002
    on_press:
      then:
        lambda: 'id(sunrise_communicator_error)->status_set_error("Sunrise communications error");'
    on_release:
      then:
        lambda: 'id(sunrise_communicator_error)->status_clear_error();'
  - platform: modbus_controller
#    name: "CO2 Sensor Algorithm Error"
    id: sunrise_algorithm_error
    entity_category: diagnostic
    modbus_controller_id: sunrise_sensor
    register_type: read
    address: 0x00
    bitmask: 0x0004
    on_press:
      then:
        lambda: 'id(sunrise_algorithm_error)->status_set_error("Sunrise algorithm error");'
    on_release:
      then:
        lambda: 'id(sunrise_algorithm_error)->status_clear_error();'
  - platform: modbus_controller
#    name: "CO2 Sensor Calibration Error"
    id: sunrise_calibration_error
    entity_category: diagnostic
    modbus_controller_id: sunrise_sensor
    register_type: read
    address: 0x00
    bitmask: 0x0008
    on_press:
      then:
        lambda: 'id(sunrise_calibration_error)->status_set_warning("Sunrise calibration error");'
    on_release:
      then:
        lambda: 'id(sunrise_calibration_error)->status_clear_warning();'
  - platform: modbus_controller
#    name: "CO2 Sensor Self-diagnostics Error"
    id: sunrise_self_diagnostics_error
    entity_category: diagnostic
    modbus_controller_id: sunrise_sensor
    register_type: read
    address: 0x00
    bitmask: 0x0010
    on_press:
      then:
        lambda: 'id(sunrise_self_diagnostics_error)->status_set_error("Sunrise self-diagnostics error");'
    on_release:
      then:
        lambda: 'id(sunrise_self_diagnostics_error)->status_clear_error();'
  - platform: modbus_controller
#    name: "CO2 Sensor Out of Range"
    id: sunrise_out_of_range
    entity_category: diagnostic
    modbus_controller_id: sunrise_sensor
    register_type: read
    address: 0x00
    bitmask: 0x0020
    on_press:
      then:
        lambda: 'id(sunrise_out_of_range)->status_set_warning("Sunrise out of range");'
    on_release:
      then:
        lambda: 'id(sunrise_out_of_range)->status_clear_warning();'
  - platform: modbus_controller
#    name: "CO2 Memory Error"
    id: sunrise_memory_error
    entity_category: diagnostic
    modbus_controller_id: sunrise_sensor
    register_type: read
    address: 0x00
    bitmask: 0x0040
    on_press:
      then:
        lambda: 'id(sunrise_memory_error)->status_set_error("Sunrise memory error");'
    on_release:
      then:
        lambda: 'id(sunrise_memory_error)->status_clear_error();'
  - platform: modbus_controller
#    name: "CO2 Sensor Measurement Not Ready"
    id: sunrise_measurement_not_ready
    entity_category: diagnostic
    modbus_controller_id: sunrise_sensor
    register_type: read
    address: 0x00
    bitmask: 0x80
    on_press:
      then:
        lambda: 'id(sunrise_measurement_not_ready)->status_set_warning("Sunrise measurement not ready");'
    on_release:
      then:
        lambda: 'id(sunrise_measurement_not_ready)->status_clear_warning();'
  - platform: modbus_controller
#    name: "CO2 Sensor Low Voltage"
    id: sunrise_low_voltage
    entity_category: diagnostic
    modbus_controller_id: sunrise_sensor
    register_type: read
    address: 0x00
    bitmask: 0x0100
    on_press:
      then:
        lambda: 'id(sunrise_low_voltage)->status_set_warning("Sunrise low voltage");'
    on_release:
      then:
        lambda: 'id(sunrise_low_voltage)->status_clear_warning();'
  - platform: modbus_controller
#    name: "CO2 Sensor Measurement Timeout"
    id: sunrise_measurement_timeout
    entity_category: diagnostic
    modbus_controller_id: sunrise_sensor
    register_type: read
    address: 0x00
    bitmask: 0x0200
    on_press:
      then:
        lambda: 'id(sunrise_measurement_timeout)->status_set_error("Sunrise measurement timeout");'
    on_release:
      then:
        lambda: 'id(sunrise_measurement_timeout)->status_clear_error();'
  - platform: modbus_controller
#    name: "CO2 Sensor Abnormal Signal Level"
    id: sunrise_abnormal_signal_level
    entity_category: diagnostic
    modbus_controller_id: sunrise_sensor
    register_type: read
    address: 0x00
    bitmask: 0x0400
    on_press:
      then:
        lambda: 'id(sunrise_abnormal_signal_level)->status_set_warning("Sunrise abnormal signal level");'
    on_release:
      then:
        lambda: 'id(sunrise_abnormal_signal_level)->status_clear_warning();'
  - platform: modbus_controller
#    name: "CO2 Sensor Scale Factor Error"
    id: sunrise_scale_factor_error
    entity_category: diagnostic
    modbus_controller_id: sunrise_sensor
    register_type: read
    address: 0x00
    bitmask: 0x8000
    on_press:
      then:
        lambda: 'id(sunrise_scale_factor_error)->status_set_warning("Sunrise scale factor error");'
    on_release:
      then:
        lambda: 'id(sunrise_scale_factor_error)->status_clear_warning();'

#text_sensor:
#  - platform: modbus_controller
#    name: "CO2 Sensor Firmware Version"
#    internal: true
#    id: sunrise_firmware_version
#    entity_category: diagnostic
#    modbus_controller_id: sunrise_sensor
#    register_type: read
#    address: 0x1C
#    raw_encode: COMMA
#  - platform: modbus_controller
#    name: "CO2 Sensor Serial Number"
#    internal: true
#    id: sunrise_serial_number
#    entity_category: diagnostic
#    modbus_controller_id: sunrise_sensor
#    register_type: read
#    address: 0x1D
#    register_count: 2
#    raw_encode: HEXBYTES