Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ A [Home Assistant][homeassistant] integration that creates a collection of [Nice
- Temperature
- Load
- RPM
- Power
- Most Recent Mining Payout

None of the sensors are added by default. See installation instructions for available configuration options.
Expand Down
1 change: 1 addition & 0 deletions custom_components/nicehash/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
ICON_PULSE = "mdi:pulse"
ICON_THERMOMETER = "mdi:thermometer"
ICON_SPEEDOMETER = "mdi:speedometer"
ICON_POWER = "mdi:power-plug"

# Platforms
SENSOR = "sensor"
Expand Down
46 changes: 46 additions & 0 deletions custom_components/nicehash/device_sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
ICON_PULSE,
ICON_THERMOMETER,
ICON_SPEEDOMETER,
ICON_POWER,
NICEHASH_ATTRIBUTION,
)
from .coordinators import MiningRigsDataUpdateCoordinator
Expand Down Expand Up @@ -381,3 +382,48 @@ def device_state_attributes(self):
"rig": self._rig_name,
}

class DevicePowerSensor(DeviceSensor):
"""
Displays power of a mining rig device
"""

@property
def name(self):
"""Sensor name"""
return f"{self._device_name} Power"

@property
def unique_id(self):
"""Unique entity id"""
return f"{self._device_id}:power"

@property
def state(self):
"""Sensor state"""
device = self._get_device()
if device:
self._power = device.power
else:
self._power = 0

return self._power

@property
def icon(self):
"""Sensor icon"""
return ICON_POWER

@property
def unit_of_measurement(self):
"""Sensor unit of measurement"""
return "W"

@property
def device_state_attributes(self):
"""Sensor device state attributes"""
return {
ATTR_ATTRIBUTION: NICEHASH_ATTRIBUTION,
"power": self._power,
"rig": self._rig_name,
}

1 change: 1 addition & 0 deletions custom_components/nicehash/nicehash.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def __init__(self, data: dict):
self.load = float(data.get("load"))
self.rpm = float(data.get("revolutionsPerMinute"))
self.speeds = data.get("speeds")
self.power = float(data.get("powerUsage"))


class MiningRig:
Expand Down
2 changes: 2 additions & 0 deletions custom_components/nicehash/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
)
from .device_sensors import (
DeviceAlgorithmSensor,
DevicePowerSensor,
DeviceSpeedSensor,
DeviceStatusSensor,
DeviceLoadSensor,
Expand Down Expand Up @@ -192,5 +193,6 @@ def create_device_sensors(mining_rigs, coordinator):
device_sensors.append(DeviceTemperatureSensor(coordinator, rig, device))
device_sensors.append(DeviceLoadSensor(coordinator, rig, device))
device_sensors.append(DeviceRPMSensor(coordinator, rig, device))
device_sensors.append(DevicePowerSensor(coordinator, rig, device))

return device_sensors