Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More system health variables #320

Open
TV456 opened this issue Nov 1, 2023 · 4 comments
Open

More system health variables #320

TV456 opened this issue Nov 1, 2023 · 4 comments
Labels
enhancement New feature or request planned To be implemented in future release

Comments

@TV456
Copy link

TV456 commented Nov 1, 2023

The MikroTik Router Integration does not yet supply all my system health items. I am missing fan 3 and fan 4, poe-out-consumptuon, psu1-current, psu1-voltage, psu2-current and psu2-voltages.

I have altered the sensor_types.py file and tested it.

I have added:

UnitOfElectricCurrent

to:

from homeassistant.const import ()

And added the following sensors:

MikrotikSensorEntityDescription(
    key="system_fan3-speed",
    name="Fan3 speed",
    icon="mdi:fan",
    native_unit_of_measurement=REVOLUTIONS_PER_MINUTE,
    device_class=None,
    state_class=SensorStateClass.MEASUREMENT,
    entity_category=EntityCategory.DIAGNOSTIC,
    ha_group="System",
    data_path="health",
    data_attribute="fan3-speed",
    data_name="",
    data_uid="",
    data_reference="",
),
MikrotikSensorEntityDescription(
    key="system_fan4-speed",
    name="Fan4 speed",
    icon="mdi:fan",
    native_unit_of_measurement=REVOLUTIONS_PER_MINUTE,
    device_class=None,
    state_class=SensorStateClass.MEASUREMENT,
    entity_category=EntityCategory.DIAGNOSTIC,
    ha_group="System",
    data_path="health",
    data_attribute="fan4-speed",
    data_name="",
    data_uid="",
    data_reference="",
),
MikrotikSensorEntityDescription(
    key="system_poe_out_consumption",
    name="PoE out power consumption",
    icon="mdi:transmission-tower",
    native_unit_of_measurement=UnitOfPower.WATT,
    suggested_unit_of_measurement=UnitOfPower.WATT,
    suggested_display_precision=1,
    device_class=SensorDeviceClass.POWER,
    state_class=SensorStateClass.MEASUREMENT,
    entity_category=EntityCategory.DIAGNOSTIC,
    ha_group="System",
    data_path="health",
    data_attribute="poe-out-consumption",
    data_name="",
    data_uid="",
    data_reference="",
),
MikrotikSensorEntityDescription(
    key="system_psu1_current",
    name="PSU 1 power consumption",
    icon="mdi:lightning-bolt-circle",
    native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
    suggested_unit_of_measurement=UnitOfElectricCurrent.MILLIAMPERE,
    suggested_display_precision=1,
    device_class=SensorDeviceClass.CURRENT,
    state_class=SensorStateClass.MEASUREMENT,
    entity_category=EntityCategory.DIAGNOSTIC,
    ha_group="System",
    data_path="health",
    data_attribute="psu1-current",
    data_name="",
    data_uid="",
    data_reference="",
),
MikrotikSensorEntityDescription(
    key="system_psu1_voltage",
    name="PSU 1 Voltage",
    icon="mdi:lightning-bolt",
    native_unit_of_measurement=UnitOfElectricPotential.VOLT,
    suggested_unit_of_measurement=UnitOfElectricPotential.VOLT,
    suggested_display_precision=1,
    device_class=SensorDeviceClass.VOLTAGE,
    state_class=SensorStateClass.MEASUREMENT,
    entity_category=EntityCategory.DIAGNOSTIC,
    ha_group="System",
    data_path="health",
    data_attribute="psu1-voltage",
    data_name="",
    data_uid="",
    data_reference="",
),
MikrotikSensorEntityDescription(
    key="system_psu2_current",
    name="PSU 2 power consumption",
    icon="mdi:lightning-bolt-circle",
    native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
    suggested_unit_of_measurement=UnitOfElectricCurrent.MILLIAMPERE,
    suggested_display_precision=1,
    device_class=SensorDeviceClass.CURRENT,
    state_class=SensorStateClass.MEASUREMENT,
    entity_category=EntityCategory.DIAGNOSTIC,
    ha_group="System",
    data_path="health",
    data_attribute="psu2-current",
    data_name="",
    data_uid="",
    data_reference="",
),
MikrotikSensorEntityDescription(
    key="system_psu2_voltage",
    name="PSU 2 Voltage",
    icon="mdi:lightning-bolt",
    native_unit_of_measurement=UnitOfElectricPotential.VOLT,
    suggested_unit_of_measurement=UnitOfElectricPotential.VOLT,
    suggested_display_precision=1,
    device_class=SensorDeviceClass.VOLTAGE,
    state_class=SensorStateClass.MEASUREMENT,
    entity_category=EntityCategory.DIAGNOSTIC,
    ha_group="System",
    data_path="health",
    data_attribute="psu2-voltage",
    data_name="",
    data_uid="",
    data_reference="",
),

Thanks to your, @tomaae, great work, this was quite easily implemented and the sensors showed up immediately after HomeAssistant restart. I hope you add these sensors with the next update.

For the record: fan 3 and fan 4 are added to my router aftermarket to optimize airflow and RouterOS picks up their respectable variables automatically.

@TV456 TV456 added the enhancement New feature or request label Nov 1, 2023
@tomaae
Copy link
Owner

tomaae commented Nov 4, 2023

Yea, there are many mikrotik devices with different health sensors.
Can you give me output of /system/health/print terse?

@TV456
Copy link
Author

TV456 commented Nov 5, 2023

Hereby:

/system/health/print terse

0 name=poe-out-consumption value=21.8 type=W
1 name=cpu-temperature value=57 type=C
2 name=fan1-speed value=1485 type=RPM
3 name=fan2-speed value=1635 type=RPM
4 name=fan3-speed value=2280 type=RPM
5 name=fan4-speed value=2415 type=RPM
6 name=board-temperature1 value=29 type=C
7 name=psu1-voltage value=26.4 type=V
8 name=psu2-voltage value=52.8 type=V
9 name=psu1-current value=0 type=A
10 name=psu2-current value=0.4 type=A

@tomaae tomaae added the planned To be implemented in future release label Nov 5, 2023
@ffries
Copy link

ffries commented Nov 24, 2023

Great, how can I get power consumption from my Mikrotik devices?
CRS328-24P-4S+

/system/health/print terse
0 name=poe-out-consumption value=21.9 type=W
1 name=cpu-temperature value=52 type=C
2 name=sfp-temperature value=36 type=C
3 name=fan1-speed value=0 type=RPM
4 name=fan2-speed value=0 type=RPM
5 name=board-temperature1 value=30 type=C
6 name=psu1-voltage value=26.4 type=V
7 name=psu2-voltage value=52.7 type=V
8 name=psu1-current value=0.1 type=A
9 name=psu2-current value=0.3 type=A

@TV456
Copy link
Author

TV456 commented Nov 25, 2023

@ffries

Alter (copy and paste) the sensor_types.py like the first post exact as described and you should be good to go.

Alternatively you can add the following lines to the end of the file sensor_types.py:

from homeassistant.const import (
    UnitOfElectricCurrent,
)

SENSOR_TYPES += (
    MikrotikSensorEntityDescription(
        key="system_fan3-speed",
        name="Fan3 speed",
        icon="mdi:fan",
        native_unit_of_measurement=REVOLUTIONS_PER_MINUTE,
        device_class=None,
        state_class=SensorStateClass.MEASUREMENT,
        entity_category=EntityCategory.DIAGNOSTIC,
        ha_group="System",
        data_path="health",
        data_attribute="fan3-speed",
        data_name="",
        data_uid="",
        data_reference="",
    ),
    MikrotikSensorEntityDescription(
        key="system_fan4-speed",
        name="Fan4 speed",
        icon="mdi:fan",
        native_unit_of_measurement=REVOLUTIONS_PER_MINUTE,
        device_class=None,
        state_class=SensorStateClass.MEASUREMENT,
        entity_category=EntityCategory.DIAGNOSTIC,
        ha_group="System",
        data_path="health",
        data_attribute="fan4-speed",
        data_name="",
        data_uid="",
        data_reference="",
    ),
    MikrotikSensorEntityDescription(
        key="system_poe_out_consumption",
        name="PoE out power consumption",
        icon="mdi:transmission-tower",
        native_unit_of_measurement=UnitOfPower.WATT,
        suggested_unit_of_measurement=UnitOfPower.WATT,
        suggested_display_precision=1,
        device_class=SensorDeviceClass.POWER,
        state_class=SensorStateClass.MEASUREMENT,
        entity_category=EntityCategory.DIAGNOSTIC,
        ha_group="System",
        data_path="health",
        data_attribute="poe-out-consumption",
        data_name="",
        data_uid="",
        data_reference="",
    ),
    MikrotikSensorEntityDescription(
        key="system_psu1_current",
        name="PSU 1 power consumption",
        icon="mdi:lightning-bolt-circle",
        native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
        suggested_unit_of_measurement=UnitOfElectricCurrent.MILLIAMPERE,
        suggested_display_precision=1,
        device_class=SensorDeviceClass.CURRENT,
        state_class=SensorStateClass.MEASUREMENT,
        entity_category=EntityCategory.DIAGNOSTIC,
        ha_group="System",
        data_path="health",
        data_attribute="psu1-current",
        data_name="",
        data_uid="",
        data_reference="",
    ),
    MikrotikSensorEntityDescription(
        key="system_psu1_voltage",
        name="PSU 1 Voltage",
        icon="mdi:lightning-bolt",
        native_unit_of_measurement=UnitOfElectricPotential.VOLT,
        suggested_unit_of_measurement=UnitOfElectricPotential.VOLT,
        suggested_display_precision=1,
        device_class=SensorDeviceClass.VOLTAGE,
        state_class=SensorStateClass.MEASUREMENT,
        entity_category=EntityCategory.DIAGNOSTIC,
        ha_group="System",
        data_path="health",
        data_attribute="psu1-voltage",
        data_name="",
        data_uid="",
        data_reference="",
    ),
    MikrotikSensorEntityDescription(
        key="system_psu2_current",
        name="PSU 2 power consumption",
        icon="mdi:lightning-bolt-circle",
        native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
        suggested_unit_of_measurement=UnitOfElectricCurrent.MILLIAMPERE,
        suggested_display_precision=1,
        device_class=SensorDeviceClass.CURRENT,
        state_class=SensorStateClass.MEASUREMENT,
        entity_category=EntityCategory.DIAGNOSTIC,
        ha_group="System",
        data_path="health",
        data_attribute="psu2-current",
        data_name="",
        data_uid="",
        data_reference="",
    ),
    MikrotikSensorEntityDescription(
        key="system_psu2_voltage",
        name="PSU 2 Voltage",
        icon="mdi:lightning-bolt",
        native_unit_of_measurement=UnitOfElectricPotential.VOLT,
        suggested_unit_of_measurement=UnitOfElectricPotential.VOLT,
        suggested_display_precision=1,
        device_class=SensorDeviceClass.VOLTAGE,
        state_class=SensorStateClass.MEASUREMENT,
        entity_category=EntityCategory.DIAGNOSTIC,
        ha_group="System",
        data_path="health",
        data_attribute="psu2-voltage",
        data_name="",
        data_uid="",
        data_reference="",
    ),
)

Note: considering your system health variables, you haven't added custom fans to your MikroTik router (which is optional), so fan 3 and fan 4 will report 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request planned To be implemented in future release
Projects
None yet
Development

No branches or pull requests

3 participants