TheThingSystem / steward

The Thing System is a set of software components and network protocols that aims to fix the Internet of Things. Our steward software is written in node.js making it both portable and easily extensible. It can run on your laptop, or fit onto a small single board computer like the Raspberry Pi.
http://thethingsystem.com
Other
346 stars 81 forks source link

add Telldus-live support #206

Closed mrose17 closed 10 years ago

mrose17 commented 10 years ago

@torkelsson - i'm going to make a quick sprint on this. do you think you can test it with your setup sometime next week. my guess is that we're talking about 30m of your time spread out over 2 or 3 nights, as we interate

thanks!

mrose17 commented 10 years ago

thanks for the reply. based on your explanation, i've made two changes:

first, the steward will update the level reported by telldus only if status='dim'. in that case, it will also set status to either 'on' or 'off', depending on whether the level is non-zero or not.

second, if the steward is told to perform an 'on' with a level of 0, it will perform an 'on' with a level of 100.

get the latest and try again… thanks!

torkelsson commented 10 years ago

I'll will try it as soon as possible, unfortunately I will be away most part of the week. Hopefully I will get a change to try it by the end of the week.

torkelsson commented 10 years ago

Turning on/off seems to work in most cases. Sometimes when I switch if off it still thinks the level is 100, but it turns it off.

Changing the dim-level does not work at all (and nothing in the log) :-(

Log at https://www.torkel.se/misc/steward-2014-05-25.log

Setting the level to 100 seems to be reasonable. Alternatives would be to either set it to a predefined value (changed in settings) or remember the last value you set it too? Don't know if either of the alternatives are possible and/or in line with the philosophy of TTS?

mrose17 commented 10 years ago

I hope to look at this later today!

mrose17 commented 10 years ago

when you turn a light off, it shouldn't effect the level. the reason is that when you turn it on again, you'll get back the same level.

it is a long-standing issue, that the level should persist across steward reboots (it doesn't).

although not germane to this issue, when a hue lightbulb loses power and then gets powered up again, it goes to 100% white. the steward should probably set it back to a previous level…

what do you think?

mrose17 commented 10 years ago

i think that these are the log entries for the dimmer:

    >>> telldus previous setting {"status":"dim","level":"255"}
    >>> dimmer  previous setting {"status":"on","level":100}
    info: [switch] device/18 Ute: Garage/Dörr level=0
    >>> dimmer perform command {"perform":"off","level":0}
    >>> telldus current  setting {"status":"off","level":"255"}
    >>> dimmer  current  setting {"status":"off","level":100}
    >>> telldus previous setting {"status":"off","level":"255"}
    >>> dimmer  previous setting {"status":"off","level":100}
    info: [switch] device/18 Ute: Garage/Dörr level=100
    >>> dimmer perform command {"perform":"on","level":255}
    >>> telldus current  setting {"status":"on","level":255}
    >>> dimmer  current  setting {"status":"on","level":0}

i'm still studying it...

webchickbot commented 10 years ago

although not germane to this issue, when a hue lightbulb loses power and then gets powered up >again, it goes to 100% white. the steward should probably set it back to a previous level… what do you think?

Yes, please! I am using the thing system in an art gallery environment and it is really useful to preserve the hue after all of the work getting the color perfect. Or having the numeric color value displayed so one could enter the exact value if it were lost would be superb!

Also, being able to group bulbs so you can turn them off and on in sets would be very useful. I know this is possible with the voice UI - but it would be useful in the visual UI as well.

mrose17 commented 10 years ago

@webchickbot - go ahead and open up two issues, one for each...

mrose17 commented 10 years ago

ok, get the latest and try the dimmer. all you really need to report is the logs like this: the dimmer was on and i turned it off with the client:

    >>> telldus previous setting {"status":"dim","level":"255"}
    >>> dimmer  previous setting {"status":"on","level":100}
    info: [switch] device/18 Ute: Garage/Dörr level=0
    >>> dimmer perform command {"perform":"off","level":0}
    >>> telldus current  setting {"status":"off","level":"255"}
    >>> dimmer  current  setting {"status":"off","level":100}

    the dimmer turned off. i then turned it back on with the client:

    >>> telldus previous setting {"status":"off","level":"255"}
    >>> dimmer  previous setting {"status":"off","level":100}
    info: [switch] device/18 Ute: Garage/Dörr level=100
    >>> dimmer perform command {"perform":"on","level":255}
    >>> telldus current  setting {"status":"on","level":255}
    >>> dimmer  current  setting {"status":"on","level":0}

    the dimmer turned on. i then set the level to 50%
…

thanks!

torkelsson commented 10 years ago

As long as the level is saved between restarts/reboots of the steward and it handles changes of the level outside the steward (when the dimmer is on), i.e it saves the level it reads from telldus live if it is non zero, it think it would be great.

By the way, I still get a "missing perform element" when trying to change the level if the dimmer is off:

error: [manage] wss 192.168.1.29 36241 /manage path=/api/v1/device/perform/18, requestID=101, perform=, parameter={} warning: [manage] wss 192.168.1.29 36241 /manage permanent=true, diagnostic=missing perform element, requestID=101, event=device performance info: [server] wss 192.168.1.29 36241 /manage loopback=false, subnet=true, local=true, remoteAddress=192.168.1.29, remotePort=36241, secure=false, clientSerialNo=81, event=close, code=1000, message=

The dimmer was off, and I turned it on:

telldus previous setting {"status":"dim","level":"0"} dimmer previous setting {"status":"off","level":0} info: [switch] device/18 Ute: Garage/Dörr level=100 dimmer perform command {"perform":"on","level":255} telldus current setting {"status":"dim","level":255} dimmer current setting {"status":"on","level":100}

and changed the level to 50%:

[nothing in the log. The actual level of the lamp didn't change, but part of the steward thinks it is at the new level until it get an update from Telldus live]:

steward1

The dimmer is set to 46%, outside of the steward. Changing it to ~90%, same behavior as above.

I guess I should try to understand the code, so that I can help you fix it.

mrose17 commented 10 years ago

i think that i'm not doing well in debugging this, so it's a good time for you to look at the code.

but, before you start: please get the latest and try one more time. if it's still not right, then keep reading!

here is where you want to look: look at the perform method in switch-telldus-dimmer.js where you see the first call to console.log -- you can ignore anything in that method above that line. the other place to look is the update method.

here is how perform works:

params.level is from 0..100 - if the perform verb is 'off', it is set to zero; otherwise, it's 'on' and params.level defaults to the current level in the steward. if params.level is invalid (<0 or >100) or is 0, it is set to 100.

level is then calculated as being (level * 255) / 100 - the dimDevice command is then given, and assuming no error occurs:

the update method takes the telldus values (name, online, status, statevalue) and updates the steward values.

thanks for your patience!

torkelsson commented 10 years ago

@mrose17 I think I finally nailed it :-)