My sensors value representation

I am trying to build my own sensors based on DIY instructions according to mysensors. I have successfully built a serial gateway that i connected to home assistant and linked trough configuration like this:

     - device: '/dev/ttyUSB0'
   version: '2.3'

I have also built Air quality sensor based on CCS811 chip that reports CO2 and TVOC values back to serial gateway. the sketch I used for the sensor is as follows:

// Enable debug prints to serial monitor
#define MY_DEBUG

// Enable and select radio type attached
#define MY_RADIO_RF24
// Enable encryption

#include <MySensors.h> // MySensors Library
#include <Wire.h>    // I2C library
#include "ccs811.h"  // CCS811 library

// Wiring for ESP8266 NodeMCU boards: VDD to 3V3, GND to GND, SDA to D2, SCL to D1, nWAKE to D3 (or GND)
CCS811 ccs811(3); // nWAKE on 3

#define CHILD_ID_AIQ_CO2 0

uint32_t SLEEP_TIME = 3*1000; // Sleep time between reads (in milliseconds)

float valAIQ =0.0;
float lastAIQ =0.0;

float valAIQ_TVOC =0.0;
float lastAIQ_TVOC =0.0;

MyMessage msg_co2(CHILD_ID_AIQ_CO2, V_LEVEL);
MyMessage msg_co2_unit(CHILD_ID_AIQ_CO2, V_UNIT_PREFIX);

MyMessage msg_tvoc(CHILD_ID_AIQ_TVOC, V_LEVEL);
MyMessage msg_tvoc_unit(CHILD_ID_AIQ_TVOC, V_UNIT_PREFIX);

void setup() {
#ifdef MY_DEBUG  
  // Enable serial
  Serial.print("setup: ccs811 lib  version: "); Serial.println(CCS811_VERSION);
  // Enable I2C
  // Enable CCS811
  ccs811.set_i2cdelay(50); // Needed for ESP8266 because it doesn't handle I2C clock stretch correctly
  bool ok= ccs811.begin();
  while( !ok ) {
    Serial.println("setup: CCS811 begin FAILED; Trying again");
    ok= ccs811.begin();
#ifdef MY_DEBUG 
  // Print CCS811 versions
  Serial.print("setup: hardware    version: "); Serial.println(ccs811.hardware_version(),HEX);
  Serial.print("setup: bootloader  version: "); Serial.println(ccs811.bootloader_version(),HEX);
  Serial.print("setup: application version: "); Serial.println(ccs811.application_version(),HEX);
  // Start measuring
  ok= ccs811.start(CCS811_MODE_1SEC);
  if( !ok ) Serial.println("setup: CCS811 start FAILED");

void presentation()
  // Send the sketch version information to the gateway and Controller
  sendSketchInfo("AIQ Sensor CO2 CCS811", "1.0");

  // Register all sensors to gateway (they will be created as child devices)
void loop() {
  // Read
  uint16_t eco2, etvoc, errstat, raw;,&etvoc,&errstat,&raw); 
  // Print measurement results based on status
  if( errstat==CCS811_ERRSTAT_OK ) { 
    if ((eco2 != lastAIQ)&&(abs(eco2-lastAIQ)>=10)) {
      lastAIQ = ceil(eco2);
    if ((etvoc != lastAIQ_TVOC)&&(abs(etvoc-lastAIQ_TVOC)>=10)) {
      lastAIQ_TVOC = ceil(etvoc);
#ifdef MY_DEBUG    
    Serial.print("CCS811: ");
    Serial.print("eco2=");  Serial.print(eco2);     Serial.print(" ppm  ");
    Serial.print("etvoc="); Serial.print(etvoc);    Serial.print(" ppb  ");
  } else if( errstat==CCS811_ERRSTAT_OK_NODATA ) {
    //Serial.println("CCS811: waiting for (new) data");
  } else if( errstat & CCS811_ERRSTAT_I2CFAIL ) { 
    Serial.println("CCS811: I2C error");
  } else {
    Serial.print("CCS811: errstat="); Serial.print(errstat,HEX); 
    Serial.print("="); Serial.println( ccs811.errstat_str(errstat) ); 
  // Wait
  sleep(SLEEP_TIME); //sleep for: sleepTime

Now, I have several issues with my configuration/implementation. In home assistent the reported values seem to be treated as “text” state rather than “value” state. What i mean is that i get history of the sensor like this:

instead of a chart. Furthermore, I do not get the units I report from my sensor. According the documentation it should be possible.

What I have missed or done wrong?

A sensor entity must have a unit_of_measurement attribute for its history to be displayed in a graph. If the sensor does not create that attribute you can do it via Customizations.

Thanks, adding unit through customization works:

However, why does it not work when sending the unit from the sensor itself during presentation?

Sorry, couldn’t tell you. I know nothing about mysensors. However, you might want to check this.