hthiery / python-fritzhome

Python Library to access AVM Fritz!Box homeautomation
MIT License
52 stars 37 forks source link

Add full support for Fritz!DECT 500 light bulbs #45

Closed DL6ER closed 3 years ago

DL6ER commented 3 years ago

This adds FritzhomeDeviceLightBulb along with everything needed to control these light bulbs. Tests are included and pass.

The following examples all expect you to have done something like

from pyfritzhome import Fritzhome
f = Fritzhome("192.168.1.1", "fritz_smarthome", 'password')
f.login()
device=f.get_device_by_ain("13011 0003111-1") # substitute your own AIN

Turn on, off, toggle light bulb

device.set_state_on()
device.set_state_off()
device.set_state_toggle()

Dimming

The brightness can be set either via a raw value (ranging from 0 to 255) or via a percentage (from 0 to 100):

device.set_level(250)
device.set_level_percentage(40)

Colors

The Fritz!DECT 500 light bulb supports only a discrete set of colors, arbitrary colors are not possible:

Von den Colordefaults abweichende HueSaturation- oder Farbtemperatur-Werte sind unzulässsig. Abweichende Werte werden vom setcolor-switchcmd bzw. setcolortemperatur-switchcmd verworfen source, see Section 3.5

I have verfied this also experimentally. Hence, it is necessary to first source the available colors and use one of them for setting the color of the light bulb:

colors = device.get_colors()
print(colors)
# {
# 'Rot': [
#     ('358', '180', '230'),
#     ('358', '112', '237'),
#     ('358', '54', '245')
#     ],
# 'Orange': [
#     ('35', '214', '255'),
#     ('35', '140', '255'),
#     ('35', '72', '255')
#     ],
# 'Gelb': [
#     ('52', '153', '252'),
#     ('52', '102', '252'),
#     ('52', '51', '255')
#     ],
# 'Grasgrün': [
#     ('92', '123', '248'),
#     ('92', '79', '250'),
#     ('92', '38', '252')
#     ],
# 'Grün': [
#     ('120', '160', '220'),
#     ('120', '82', '232'),
#     ('120', '38', '242')
#     ],
# 'Türkis': [
#     ('160', '145', '235'),
#     ('160', '84', '242'),
#     ('160', '41', '248')
#     ],
# 'Cyan': [
#     ('195', '179', '255'),
#     ('195', '118', '255'),
#     ('195', '59', '255')
#     ],
# 'Himmelblau': [
#     ('212', '169', '252'),
#     ('212', '110', '252'),
#     ('212', '56', '255')
#     ],
# 'Blau': [
#     ('225', '204', '255'),
#     ('225', '135', '255'),
#     ('225', '67', '255')
#     ],
# 'Violett': [
#     ('266', '169', '250'),
#     ('266', '110', '250'),
#     ('266', '54', '252')
#     ],
# 'Magenta': [
#     ('296', '140', '250'),
#     ('296', '92', '252'),
#     ('296', '46', '255')
#     ],
# 'Pink': [
#     ('335', '180', '255'),
#     ('335', '107', '248'),
#     ('335', '51', '250')
#     ]
# }

The color names depend on the language of your Fritz!Box.

In this example, there are three variants of each color available, you can set one of them using, e.g.:

device.set_color(colors["Rot"][1])

White temperature

Likewise, only distinct white temperatures between cold and warm white are supported. First, get the supported temperatures using

device.get_color_temps()
['2700', '3000', '3400', '3800', '4200', '4700', '5300', '5900', '6500']

and use one of them to set a white light color:

device.set_color_temp(2700)
hthiery commented 3 years ago

thank you