Last active
April 4, 2023 10:48
-
-
Save Superkikim/fe3e3161dc42bf34a7bb10966318a9e3 to your computer and use it in GitHub Desktop.
home assistant MaxSmart / Revogi
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 MaxSmart 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 = 'MaxSmart switch' | |
ATTR_CURRENT_CONSUMPTION = 'Current Consumption' | |
ATTR_CURRENT_CONSUMPTION_UNIT = 'W' | |
ATTR_CURRENT_AMPAGE = 'Current Amps' | |
ATTR_CURRENT_AMPAGE_UNIT = 'A' | |
CONF_PORTS = 'ports' | |
CONF_OUTLETS = 'outlets' | |
REQ_CONF = [CONF_HOST, CONF_OUTLETS] | |
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ | |
vol.Required(CONF_HOST): cv.string, | |
vol.Required(CONF_PORTS): cv.positive_int, | |
vol.Optional(CONF_OUTLETS): {cv.positive_int: cv.string}, | |
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string | |
}) | |
def setup_platform(hass, config, add_devices, discovery_info=None): | |
"""Set up the outlets.""" | |
dev = [] | |
number_outlets = config.get(CONF_PORTS) # MaxSmart 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]) | |
self._now_amp = float(request['amp'][self._number-1]) | |
except (TypeError, ValueError): | |
self._now_power = None | |
_LOGGER.error('Error while reading from MaxSmart Power Outlet') |
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
# name is the name of device, either a power strip or power plug | |
# host is the IP address of the device | |
# Port is for the number of outlets (6 if it's a 6 outlet strip, 1 if it's a power plug) | |
# outlets allows to specify a name for outlets in the form of outlet_number: outlet_name | |
- platform: maxsmart | |
name: Lounge | |
host: 192.168.1.25 | |
ports: 6 | |
outlets: | |
3: Left Lamp | |
- platform: maxsmart | |
name: TV1 | |
host: 192.168.1.26 | |
ports: 6 | |
outlets: | |
1: Ampli TV | |
4: nVidia Shield |
I don't maintain it and I've given up on HASSIO. I just use flic
buttons with my phone and API calls.
You can find basic API calls on my blog.
It's in french but I'm confident you'll find your way around or use
google to translate
https://akim.sissaoui.com/informatique/maxsmart-resapi/
Le 2021-08-25T05:12:03.000+02:00, ymed85 ***@***.***> a
écrit :
***@***.*** commented on this gist.
… -------------------------
I've update to hassio 021.8.8, and
custom_components/maxsmart/switch.py [http://switch.py] with init.py
[http://init.py] don't work anymore...Some solution?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
[https://gist.github.com/fe3e3161dc42bf34a7bb10966318a9e3#gistcomment-3871296],
or unsubscribe
[https://github.com/notifications/unsubscribe-auth/ACM7BZPNUVRDA7256MUIZ7TT6RNQHANCNFSM5CYDKE7A].
Triage notifications on the go with GitHub Mobile for iOS
[https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675]
or Android
[https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email].
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've update to hassio 021.8.8, and custom_components/maxsmart/switch.py with init.py don't work anymore...Some solution?