Hey Tidbyt community!
I recently integrated my Tidbyt with Home Assistant, allowing it to adjust its brightness dynamically based on the brightness level of my room (light.room
). I wanted to map the brightness in a way that it only ranges between 20 and 80 on the Tidbyt, while the light.room
brightness in Home Assistant ranges from 0 to 255.
Here’s how I did it:
Step 1: Define the REST command
In your configuration.yaml
, add the following rest_command
to make a PATCH request to the Tidbyt API:
rest_command:
update_tidbyt_brightness:
url: "https://api.tidbyt.com/v0/devices/{device.id}"
method: PATCH
headers:
accept: "application/json"
Authorization: "Bearer YOUR_API_TOKEN" # Replace with your Tidbyt API token
Content-Type: "application/json"
payload: '{"brightness": {{ brightness }}}'
Step 2: Create the Automation
Next, create an automation that triggers when the hallway light’s brightness changes and scales it to a 20-80 range for Tidbyt:
automation:
- alias: Update Tidbyt Brightness Based on Light Brightness
trigger:
platform: state
entity_id: light.room
condition:
condition: template
value_template: "{{ state_attr('light.room', 'brightness') is not none }}"
action:
- service: rest_command.update_tidbyt_brightness
data:
brightness: "{{ ((state_attr('light.room', 'brightness') | int * (80 - 20) / 255) + 20) | round(0) }}"
Feel free to try this setup, tweak it to your needs, and share your experiences. Let me know if you have any questions or suggestions to improve this further!