Sunrise / Sunset Script

Hi guys,

i try to create a script to simulate sunrise / sunset over all the connected bulbs.
Unfortunately in the Log i get the following error and the script is not working properly

17-03-04 13:59:45 WARNING (MainThread) [homeassistant.helpers.state] reproduce_state: Unable to reproduce state <state group.lights=None; rgb_color=[254, 91, 53], brightness=20, transition=9000 @ 2017-03-04T13:59:21.302311+01:00>

Does maybe anyone have a running script for sunrise / sunset simulation?

######### Scripts

script:
sunrise:
sequence:
- service: light.turn_on
data:
entity_id: group.lights
- service: scene.turn_on
data:
entity_id: scene.sunrise_start
- service: scene.turn_on
data:
entity_id: scene.sunrise_end

sunset:
sequence:
- service: light.turn_on
data:
entity_id: group.lights
- service: scene.turn_on
data:
entity_id: scene.Home
- service: scene.turn_on
data:
entity_id: scene.sunset_end

######### Scenes

  • name: Home
    icon: mdi:home-outline
    entities:
    group.lights:
    state: on
    brightness: 204
    rgb_color: [255,67.92041905680745,0]
    color_temp: 312.5

  • name: sunrise_start
    icon: mdi:home-outline
    entities:
    group.lights:
    rgb_color: [254,91,53]
    brightness: 20

  • name: sunrise_end
    icon: mdi:home-outline
    entities:
    group.lights:
    state: on
    brightness: 204
    rgb_color: [255,67.92041905680745,0]
    color_temp: 312.5
    transition: 900000

  • name: sunset_end
    icon: mdi:toggle-switch-off
    entities:
    group.lights:
    rgb_color: [254,91,53]
    brightness: 20
    transition: 900000

Hi Thorbeen, have you solved this problem? I’ve got RGBW Yeelights and have been using the Yeelight app to trigger a sunset sequence while I’m getting ready for bed. However, I now want to automate this using Home Assistant and not be reliant on a connection to the Yeelight Singapore servers. I’ve played around with the Flux platform but can’t set it up as part of an action that I’m controlling via an input.boolean trigger independent of the time when I trigger it.

My wip solution for sunrise:

shell_command:
  yeelight_livingroom_artificial_dawn: "/home/me/.local/bin/yeelight_set_scene.sh 3 1 '50,1,16731392,1,360000,2,1700,10,540000,2,2700,100' 192.168.1.3"

with yeelight_set_scene.sh having the following content:

#!/bin/bash 
echo -ne "{\"id\": 1, \"method\": \"set_scene\", \"params\": [\"cf\",${1},${2},\"${3}\"]}\r\n" | /bin/nc -w1 ${4} 55443

the method is documented here.

I’m still pleased with tinkering these bulbs at times, I even hooked them to a boblight daemon, that works surprisingly well

3 Likes

It is no longer allowed to use rgb_color and color_temp at the same time because it will either be conflicting or redundant.

1 Like

This is 2 automations I have for some of my Yeelights. I know this is different in some way to what you are trying to achieve, but it’s more so you can get how the light values work.

This one turns on the 2 lights, 30 mins before Sunset to a normal light about 4500k (yellow/white).

# Sunset - Steps & Table #
- id: Sunset - Steps & Table
  alias: Sunset - Steps & Table
  trigger:
    platform: sun
    event: sunset
    offset: "-00:30:00"
  action:
    - service: light.turn_on
      entity_id:
        - light.steps
        - light.table
      data:
        brightness: 60
        color_temp: 222
        transition: 3

Then this one changes the color of the lights to Blue if a family member is home, and the sun sets

# Sunset - Steps & Table Turn Blue #
- id: Sunset - Steps & Table Turn Blue
  alias: Sunset - Steps and Table Turn Blue
  trigger:
    platform: sun
    event: sunset
  condition:
    condition: state
    entity_id: group.family
    state: 'home'
  action:
    service: light.turn_on
    entity_id:
      - light.steps
      - light.table
    data:
      brightness: 60
      rgb_color: [0,0,255]
      transition: 3

You will notice that the Blue color setting has an RGB value and the ‘white light’ setting uses a color temp value, which is read in mireds. To obtain the mired number, you divide 1,000,000 by the Kelvin color temp you wish to dial in, in my case it was 4500k, so that gives me a mired value of 222 which becomes the value used for color_temp.

You could use the above automation and adjust the transition time to what you want to bring the lights on slowly, or have them go off slowly based on a offset time before sunset/sunrise perhaps? I hope I am making sense, I understand me at least :slight_smile:

I had some difficulties with my Yeelights when I first got them, so I hope this helps a little at least to get the color settings right.

1 Like

There is now a Kelvin alternative that does this calculation automatically. So you can just say kelvin: 4500 rather than color_temp: 222.

1 Like

This calls the scene directly like in the yeelight app?

This calls a scene with specified sketch parameters as defined by the api :thinking: :grinning: . Would you mind reformulate ?

How long does the entire “sunrise” take? Is the total duration adjustable?

Come on @Bob_NL, the doc has big fonts, 15 min tops to skim thru :yum:
50+360000+540000ms and yes

1 Like

On a side note, it’s a pity the yeelight api call is not accessible from the hass service api … I don’t feel throwing myself in alone … wanna pair ?

@Thorbeen’s approach is definitely the most explicit. Maybe chaining the scenes/transitions would effectively be a better pattern ?

Cheers Guys,

5 months ago… long time in our digital age :stuck_out_tongue:

Have changed my system to hue in that time but still very interested in a working script for a simulated sunrise / sunset :slight_smile:

Let’s get this running

So it’s like using the sunrise scene in the yeelight app, but in home assistant?

It effectively comes close to the sunrise scene in the yeelight app.

It look cryptic, but for the gist: the bulb execute the specified composition of state transitions from time, colorspace values and brightness, yes … just like in home-assistant.

Don’t use my example as is, it’s just a dumb example or the next shellcode.

But this is just scratching an itch, again, I’m pretty sure it’ll evolve towards Thorbeen’s pattern.

When I run the shell command in a script nothing happens. I created a file with the script in home assistant directory and I’m using a script to call the shell command.

Told ya ! :yum:
IWFM … did you try to fiddle with the commanline ? What parameters are given ? An error message ?

/bin/nc -h
OpenBSD netcat (Debian patchlevel 1.130-3)
usage: ...

What would be interesting is … crunching some cropped yt videos and extract normalized rgb and/or brightness values from the timelapse to a timeserie.
Wait a minute (sorry, right brain switch) ! We could leverage this boblight pet project that I mention in post#3 for that !

Implementing a yeelight sunrise effect in ha/yeelight api context could be an option for a python dev.

3 Likes

Does this solution still works? Have you improved/changed something in the last 8 months?

works perfectly.