Revogi/MaxSmart switch component: With and without cloud polling

Hi guys.

I’m a self learner. But the road is long now because I have no clue about Python yet.

So I would need some help about developing a custom component. I have a base file which is the revogi.py file from @thejacko12354.

Note that I changed all UIDs from the examples below. Don’t bother telling me MAC are invalid. I KNOW :wink: It’s on purpose.

Revogi has two type of power sockets. One is a single socket, and one is a 6-socket strips. There are two ways of getting the details:

  1. Setup manually the devices
  2. Connect to the provider cloud. This will return the complete list of devices

This is how I imagine the configuration in yaml (my platform is named maxsmart because it’s made by revogi but sold by maxsmart and it’s not 100% equal to revogi. @thejacko12354 will most probably work on it as well if he finds it interesting).

Example without cloud polling:

  switch:
    name: Kitchen
    host: 192.168.1.12
    sockets: 6 #Number of sockets (1 for single plug, 6 for strip)
      - socket:
        port: 3
        name: lamp kitchen
      - port 5:
        name: microwave

or alternatively, allowing cloud polling:

switch:
  - platform: maxsmart
    url: www.maxsmart.ch
    username: !secret maxsmart_username
    password: !secret maxsmart_password

Now: If used without the cloud polling, I can use the file from @thejacko12354. However, I want to get the number of sockets from the configuration file instead of hard coding it in the component file. So number_outlets need to be grabbed from the sockets field int he yaml file. I didn’t get how to do that. Anyone can please clarify ?

Then, in the SmartSwitch class, I would like to set port names to the one specified in the yaml file IF specified, otherwise, default to a generic name like “devicename.socket#x”. The latter I know how to handle. But then again, grabbing data from the config file and use them in the class, I don’t understand how to do it. Would love somebody to explain.

Now the harder part: in case of cloud polling, this is how I have to proceed:

https://www.maxsmart.ch/services/ajax.html?cmd=500&json={"dev": "all"}

Below an example of the result, which comes in json:

{"code":200,"data":[{"ver":"1.30","pname":["Ampli Audio","TV","NUC","HDDs","Switch Gbs","WIFI"],"nver":"1.30","line":1,"socket_type":"UDP(Mina)","ip":"0.0.0.0","mac":"BC:2B:D7:00:YY:YY","uid":"","password":"","dateAdd":"2017-11-25 21:48:02","name":"TV2","gateway_ip":"xxx.xxx.xxx.xxx","sn":"SWP6023002003697","protect":0,"sak":"70493946264","register":1},{"ver":"1.30","pname":["Ampli TV","Tuner TV","Sunrise TV","Nvidia Shield","Transporter","Harmony"],"nver":"1.30","line":1,"socket_type":"UDP(Mina)","ip":"0.0.0.0","mac":"BC:2B:D7:00:SS:SS","uid":"","password":"","dateAdd":"2017-11-26 00:30:45","name":"TV1","gateway_ip":"xxx.xxx.xxx.xxx","sn":"SWP6023002002468","protect":0,"sak":"6865763WEVBF","register":1},{"ver":"1.30","nver":"1.30","line":1,"socket_type":"UDP(Mina)","ip":"0.0.0.0","mac":"BC:2B:D7:00:HH:HH","uid":"","password":"","dateAdd":"2017-11-28 17:39:41","name":"voiture","gateway_ip":"xxx.xxx.xxx.xxx","sn":"SWP1023002012345","protect":0,"sak":"524750712343","register":1},{"ver":"1.30","pname":["Lampe sur pied","roomba","Lampe orange","PORT4","PORT5","PORT6"],"nver":"1.30","line":1,"socket_type":"UDP(Mina)","ip":"0.0.0.0","mac":"BC:2B:D7:00:VV:VV","uid":"","password":"","dateAdd":"2017-12-01 11:51:42","name":"Salle à manger","gateway_ip":"xxx.xxx.xxx.xxx","sn":"SWP602300212345","protect":0,"sak":"6D5266712345","register":1},{"ver":"1.30","pname":["Téléphone DECT","Clavier","hassio","Chargeur USB","Camera","Casque"],"nver":"1.30","line":1,"socket_type":"UDP(Mina)","ip":"0.0.0.0","mac":"BC:2B:D7:00:XX:XX","uid":"","password":"","dateAdd":"2017-12-03 18:28:20","name":"Chargeurs","gateway_ip":"xxx.xxx.xxx.xxx","sn":"SWP6023002093829","protect":0,"sak":"494D512FFFFF","register":1},{"ver":"1.30","pname":["PORT1","PORT2","PORT3","PORT4","PORT5","PORT6"],"nver":"1.30","line":0,"socket_type":"UDP(Mina)","ip":"0.0.0.0","mac":"BC:2B:D7:00:HH:HH","uid":"","password":"","dateAdd":"2017-12-16 00:17:50","name":"PowerStation","gateway_ip":"xxx.xxx.xxx.xxx","sn":"SWP6023002023231","protect":0,"sak":"367976612153","register":1},{"ver":"1.30","pname":["Ecran gauche","Ecran centre","Ecran droit","El Gato","HP multifonction","Mac"],"nver":"1.30","line":1,"socket_type":"UDP(Mina)","ip":"0.0.0.0","mac":"BC:2B:D7:00:JJ:JJ","uid":"","password":"","dateAdd":"2017-12-16 00:18:20","name":"Bureau","gateway_ip":"xxx.xxx.xxx.xxx","sn":"SWP6023002002523","protect":0,"sak":"686F4B712340","register":1}],"response":500}

Converted to YAML, for readability and removed the info I don’t need, we get the following data:

code: 200
data:
- ver: '1.30'
  pname:
  - Ampli Audio
  - TV
  - NUC
  - HDDs
  - Switch Gbs
  - WIFI
  mac: BC:2B:D7:00:YY:YY
  name: TV2
  gateway_ip: xxx.xxx.xxx.xxx
- ver: '1.30'
  pname:
  - Ampli TV
  - Tuner TV
  - Sunrise TV
  - Nvidia Shield
  - Transporter
  - Harmony
  mac: BC:2B:D7:00:SS:SS
  name: TV1
- ver: '1.30'
  mac: BC:2B:D7:00:HH:HH
  name: voiture
- ver: '1.30'
  pname:
  - Lampe sur pied
  - roomba
  - Lampe orange
  - PORT4
  - PORT5
  - PORT6
  mac: BC:2B:D7:00:VV:VV
  name: Salle à manger
  gateway_ip: xxx.xxx.xxx.xxx
- ver: '1.30'
  pname:
  - Téléphone DECT
  - Clavier
  - hassio
  - Chargeur USB
  - Camera
  - Casque
  mac: BC:2B:D7:00:XX:XX
  name: Chargeurs
- ver: '1.30'
  pname:
  - PORT1
  - PORT2
  - PORT3
  - PORT4
  - PORT5
  - PORT6
  mac: BC:2B:D7:00:HH:HH
  name: PowerStation
  gateway_ip: xxx.xxx.xxx.xxx
- ver: '1.30'
  pname:
  - Ecran gauche
  - Ecran centre
  - Ecran droit
  - El Gato
  - HP multifonction
  - Mac
  mac: BC:2B:D7:00:JJ:JJ
  name: Bureau
  gateway_ip: xxx.xxx.xxx.xxx

Unfortunately, from the cloud, we can’t get the device IP address. This is stupid but it is so.

  • I want to check the code result. If 200 = Ok. If not, return an error
  • For each “ver:” I want to get the MAC Address
  • I want to use the MAC Address to lookup for the IP address of the device on the network: Might be possible with nmap… But I tried nmap on my hass, and it gives me erratic results… However, arp -a gives me all the devices correctly. I should be able to grab the IP address that way. How ?
  • I want then to assign the IP address to the host variable as it will be used to get and set states on the device.
  • For each “ver:” I want to create a device named with the name value
  • For each device, I want to check if there is a pname value
    • If there is a pname value, I want to create one socket per entry for this device witht the pname value
    • If there is no pname value, I want to crate only one socket for this device named with the name value

If getting the IP from the MAC is not possible, I’m affraid I’ll have to give up on the cloud polling, unless someone has another idea on how to achieve this.

So. I tried to be as exhaustive as possible. Any help is welcome. This is more a way for me to learn on how to create components, and at the same occasion, to start working with Python. And I love things well done. So I wish to be able to create a well designed component to share with the community.

Hey, did you manage do a get a maxSMART component working ?

1 Like

Hey Max.

Sorry your questions was a long time ago. Didn’t see it.

Yes, my MaxSmart are working perfecly. Have you read my article @ https://akim.sissaoui.com ?

No, got a link ? I have a Max smart 2.0 single power socket and no luck.