diff --git a/README.md b/README.md index b94752e..f0e24b0 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Monitor and control your Mikrotik device from Home Assistant. * Enable/disable Simple Queue switches * Mikrotik Accounting traffic sensors per hosts for RX/TX WAN/LAN * Device tracker for hosts in network - * System sensors (CPU, Memory, HDD) + * System sensors (CPU, Memory, HDD, Temperature) * Check firmware update * Execute scripts using switches or services * Configurable update interval diff --git a/custom_components/mikrotik_router/mikrotik_controller.py b/custom_components/mikrotik_router/mikrotik_controller.py index a089d4f..d20aefd 100644 --- a/custom_components/mikrotik_router/mikrotik_controller.py +++ b/custom_components/mikrotik_router/mikrotik_controller.py @@ -55,6 +55,7 @@ class MikrotikControllerData: self.data = { "routerboard": {}, "resource": {}, + "health": {}, "interface": {}, "bridge": {}, "bridge_host": {}, @@ -269,6 +270,9 @@ class MikrotikControllerData: if self.api.connected(): await self.hass.async_add_executor_job(self.get_system_resource) + if self.api.connected(): + await self.hass.async_add_executor_job(self.get_system_health) + if self.api.connected(): await self.hass.async_add_executor_job(self.get_script) @@ -637,6 +641,17 @@ class MikrotikControllerData: ], ) + # --------------------------- + # get_system_health + # --------------------------- + def get_system_health(self): + """Get routerboard data from Mikrotik""" + self.data["health"] = parse_api( + data=self.data["health"], + source=self.api.path("/system/health"), + vals=[{"name": "temperature", "default": "unknown"}], + ) + # --------------------------- # get_system_resource # --------------------------- diff --git a/custom_components/mikrotik_router/sensor.py b/custom_components/mikrotik_router/sensor.py index 708cb35..8753923 100644 --- a/custom_components/mikrotik_router/sensor.py +++ b/custom_components/mikrotik_router/sensor.py @@ -2,7 +2,12 @@ import logging -from homeassistant.const import CONF_NAME, ATTR_ATTRIBUTION, ATTR_DEVICE_CLASS +from homeassistant.const import ( + CONF_NAME, + ATTR_ATTRIBUTION, + ATTR_DEVICE_CLASS, + TEMP_CELSIUS, +) from homeassistant.core import callback from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -34,6 +39,15 @@ ATTR_PATH = "data_path" ATTR_ATTR = "data_attr" SENSOR_TYPES = { + "system_temperature": { + ATTR_DEVICE_CLASS: None, + ATTR_ICON: "mdi:thermometer", + ATTR_LABEL: "Temperature", + ATTR_UNIT: TEMP_CELSIUS, + ATTR_GROUP: "System", + ATTR_PATH: "health", + ATTR_ATTR: "temperature", + }, "system_cpu-load": { ATTR_DEVICE_CLASS: None, ATTR_ICON: "mdi:speedometer", diff --git a/info.md b/info.md index 5ea6908..df760a0 100644 --- a/info.md +++ b/info.md @@ -16,7 +16,7 @@ Monitor and control your Mikrotik device from Home Assistant. * Enable/disable Simple Queue switches * Mikrotik Accounting traffic sensors per hosts for RX/TX WAN/LAN * Device tracker for hosts in network - * System sensors (CPU, Memory, HDD) + * System sensors (CPU, Memory, HDD, Temperature) * Check firmware update * Execute scripts * Configurable update interval