Adding support for sinope light switch and dimmer

I want to add support for the Sinopé light switch and dimmer. I’m almost there but still having an error in the log:

2018-01-08 23:03:32 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.6/asyncio/tasks.py", line 180, in _step
    result = coro.send(None)
  File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity_component.py", line 399, in async_process_entity
    new_entity, self, update_before_add=update_before_add
  File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity_component.py", line 247, in async_add_entity
    yield from entity.async_update_ha_state()
  File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 210, in async_update_ha_state
    state = self.state
  File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 360, in state
    return STATE_ON if self.is_on else STATE_OFF
  File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 365, in is_on
    raise NotImplementedError()

The error occur when I’m reading the switch state. Do I need to add code directly in HA ? in entity.py ?

Also I’ve created it as a switch component. Is it better to make it as a light component ?

Thank You

I would add the component as a light for the dimmer since you need to set a brightness or intensity parameter. I only have the dimmer switches so I can’t confirm how you would want to add the switch only component. Feel free to DM me your code if you’d like a 2nd person testing.

I was able to setup my dimmer switches, will post the code on github soon.
Do you have both dimmer and regular sinope switches? @claudegel

Yes I’ve both. and also load controller. To be able to differentiate between all of them you will need to add:
if device["info"]["type"] == 10:
where 10 is for thermostat TH1120RF, 3000W and 4000W
20 is for floor heating thermostat TH1300RF
21 is for low power thermostat TH1400RF 24v AC
102 is for light switch SW2500RF
112 is for dimmer switch DM2500RF
and 120 is for load controller RM3250RF and RM3200RF

if you have all of them in your home it will allow to control them separately with the appropriate module in HA.

Could you send me your code for dimmer. I’m able to see all my device but still have problem sending command for them.

Did you post your code on github ?

I’ve added the code. Note that there is an issue with the sinope component and it not updating all the time. Your log file will get polluted. This is an issue that was being discussed here: Sinope Line Voltage Thermostats
https://github.com/dj21d/sinope

I hope to have some more cycles to address the issue. Feel free to edit the code, this was my quick/first attempt at making a component

Is it included in the sinope.py file for the thermostat or it’s a separate file?
In sinope.py there is only type=10 which is for the thermostat. You should have type 102 and 112 for light et dimmer.

what is your github adress for the light and dimmer component ?

Sorry about that, first commit didn’t have the light component. Same repo has it now.

A note, this will only handle the dimmer switches. I don’t have any of the regular switches to test with so I didn’t add that support.

Ok I’ve installed your code and then on restart my log were flooded with error messages.
Then I’ve made a small change in your code:

DEFAULT_NAME = ‘Sinope dimmer’

I’ve changed the default name to have something different then what I have for the thermostat so now I have ‘Sinope’ for thermostat, ‘Sinope dimmer’ for the dimmer, ‘Sinope light’ for the light switch and ‘Sinope switch’ for the load controler.
DEFAULT_NAME should be different for each sinope module I think.

The log are quiet now but with your code I’m at the same place then what I have with my code. I’m able to read the dimmer, light or switch state (intensity) but I cannot close or open the dimmer. Each time I switch the slider to turn off one dimmer after few second there is a flag at the bottom of the screen that pop up and the slider goes back to it initial state. I can’t turn on or off the dimmer.

Also when a dimmer is on. If I click on it to open the popup history I notice that the slider at the bottom is only at 50 not 100%. Would it be better to use _intensity_pct because normally _intensity goes from 0 to 254 and _intensity_pct goes from 0 to 100 (intensity percentage). I give it a try and let you know.

I’ve also changed the class name to SinopeDimmer instead of SinopeLight because I already have that one for the sinope light switch
``
for id, device in sinope_data.data.items():
if device[“info”][“type”] == 112:
devices.append(SinopeDimmer(sinope_data, id, ‘{} {}’.format(name, device[“info”][“name”])))

add_devices(devices, True)

class SinopeDimmer(Light):
``

Nice addition. I think my next project will be to break the hub out of it so that you so much overlapping code isn’t needed for the climate and light component.
The 50% intensity was just my code trying to say “If you don’t know what brightness you were before set the light to 50%” which is my preferred level. That should be changed though, since it’s not the best feature. I still need to get ahold of the Sinope api docs and see if I can find where they are saving the old intensity level of a light when it’s powered off. That would be the ideal method/value

I’ve found what you need.
Scale 1 = 1%
Range 0 = 0% OFF
1@100 = ON
101 = Recall last dim*

So setting intensity to 101 will recall the last intensity before we shut off the dimmer.

Great find. I’ve modified my code a bit and pushed to github. The slider now works on the dashboard and it will now recall the old brightness if one is not set!

With your regular light switch what kind of call is it making for turning the light on/off? Is it still using intensity? Maybe we can add the required code to my repo for it. I’m hoping once we can make the hub and fix the failed call issues we can make a PR and officially add this.

For the light switch it’s the same
intensity
0 = relay OFF
100 = relay ON (SW2500RF)

I’ll send you my code for the light switch this weekend.
I also have code for the load controller which also use intensity 0/100 for off/on

I’ve updated to 0.64.2 and nothing work. The log are flooded with:
:0:0 uncaught exception: out of memory

@claudegel Sounds like hardware issues. What are you running your home assistant on?
With my pi3 running hassio I still have 43% memory free.

I’m using the system monitor component to track this

I’m on Hassbian on Pi3. I just updated to 0.64.3 and nothing was working. I’ve updated hassbian and then it’s back again. Normally I update hasbian first and HA after but this time It was needing a second update of hassbian.
I’ll add the system monitor. Now both dimmer and light are working but not 100% of time. I’ll send you my code soon this week.
I’m a little busy now because my wife just came back from hospital for a hip replacement. Maybe some day I’ll be able to control her with HA :slight_smile:

Ok I’m ready to send you my code for dimmer, light and power switch. For dimmer It’s almost the same as what you have except that I’ve changed float for int.
How can I send you my code. By email ?