-
-
Save thejacko12354/d883f51f3747aa4b9f268f68c2d1b9f1 to your computer and use it in GitHub Desktop.
Revogi Component for Home Assistant
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Support for a Revogi Power Switch. | |
""" | |
import logging | |
import requests | |
import voluptuous as vol | |
from homeassistant.components.switch import (SwitchDevice, PLATFORM_SCHEMA) | |
from homeassistant.const import (CONF_NAME, CONF_HOST) | |
import homeassistant.helpers.config_validation as cv | |
_LOGGER = logging.getLogger(__name__) | |
DEFAULT_NAME = 'revogi switch' | |
ATTR_CURRENT_CONSUMPTION = 'Current Consumption' | |
ATTR_CURRENT_CONSUMPTION_UNIT = 'W' | |
ATTR_CURRENT_AMPAGE = 'Current Amps' | |
ATTR_CURRENT_AMPAGE_UNIT = 'A' | |
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ | |
vol.Required(CONF_HOST): cv.string, | |
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, | |
}) | |
def setup_platform(hass, config, add_devices, discovery_info=None): | |
"""Set up the aREST switches.""" | |
dev = [] | |
number_outlets = 6 # Revogi Power Strip EU | |
for number in range(1, number_outlets+1): | |
dev.append(SmartSwitch( | |
config.get(CONF_HOST), | |
config.get(CONF_NAME), | |
number)) | |
add_devices(dev) | |
class SmartSwitch(SwitchDevice): | |
"""Representation of a single outlet""" | |
def __init__(self, host, name, number): | |
"""Initialize the switch.""" | |
self._host = host | |
self._name = name | |
self._number = number | |
self._now_power = 0.0 | |
self._now_amp = 0.0 | |
self._state = False | |
@property | |
def name(self): | |
"""Return the name of the outlet.""" | |
return self._name+str(self._number) | |
@property | |
def state_attributes(self): | |
"""Return the state attributes of the device.""" | |
attrs = {} | |
attrs[ATTR_CURRENT_CONSUMPTION] = "%.1f %s" % \ | |
(self._now_power, ATTR_CURRENT_CONSUMPTION_UNIT) | |
attrs[ATTR_CURRENT_AMPAGE] = "%.1f %s" % \ | |
(self._now_amp, ATTR_CURRENT_AMPAGE_UNIT) | |
return attrs | |
@property | |
def current_power_watt(self): | |
"""Return the current power usage in watt.""" | |
return self._now_power | |
@property | |
def is_on(self): | |
"""Return Switch State""" | |
return self._state | |
def turn_on(self): | |
"""Turn the switch on.""" | |
requests.get('http://'+self._host+'/?cmd=200&json={"port":'+str(self._number)+ | |
', "state":1}') | |
def turn_off(self): | |
"""Turn the switch off.""" | |
requests.get('http://'+self._host+'/?cmd=200&json={"port":'+str(self._number)+ | |
', "state":0}') | |
def update(self): | |
"""get state from outlet.""" | |
try: | |
request = requests.get('http://'+self._host+'/?cmd=511').json()['data'] | |
_LOGGER.debug(request) | |
self._state = request['switch'][self._number-1] | |
self._now_power = float(request['watt'][self._number-1]/1000) | |
self._now_amp = float(request['amp'][self._number-1]/1000) | |
except (TypeError, ValueError): | |
self._now_power = None | |
_LOGGER.error('Error while reading from Revogi Power Outlet') | |
Sorry didn't get an notification that you commented 🙄
It's just
- platform: revogi
host: XXX.XXX.XXX.XXX
name: somename
Hello, I just purchased one of these power strips. And their web page is really broken, but the android app works.
I just installed Hass on a Ubuntu Linux distro, using hassio_install script. This all worked.
I'm comfortable at the command line. Where would the revogi.py script sit on the power strip OS? Never using Hass before, will the power bar appear on the dashboard, or is there more intervention needed?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Julian,
Thanks for sharing this. Coming from the HA forum website (https://community.home-assistant.io/t/revogi-smart-power-strip/11273) , I´m interested on setting up the revogi plug on my HA. I was able to apply your little hack on the plug it-self, but being still a newbie in HA (yet), I´m not sure what to insert on my configuration.yaml file (and also where) to benefit from your script and use it to control the plug.
Any help would be appreciated, like an extract of your config file.
Thank you in advance for your help,
Cheers,
Marc