Advertisement
Guest User

Light control

a guest
Dec 15th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.14 KB | None | 0 0
  1. #!/bin/sh
  2. save () {
  3.         if [ $state == "b" ]; then
  4.                 echo "zone=$zone;min=$min;max=$max" > ~/.milight/$zone.bright
  5.         elif [ $state == "e" ]; then
  6.                 echo "zone=$zone;min=$min;max=$max" > ~/.milight/$zone.temp
  7.         else
  8.                 echo "Unexpected case expression. Exiting"
  9.                 exit 3
  10.         fi
  11. }
  12.  
  13. load () {
  14.         if [ $state == "e" ]; then
  15.                 source ~/.milight/$zone.bright
  16.         elif [ $state == "b" ]; then
  17.                 source ~/.milight/$zone.temp
  18.         else
  19.                 echo "Unexpected case expression. Exiting"
  20.                 exit 3
  21.         fi
  22. }
  23.  
  24. licon () {
  25.         /usr/local/bin/milight.py --ip 192.168.1.133 --zone $@
  26.         save
  27.  
  28. }
  29.  
  30. #Gradually changes temperature
  31. liset () {
  32.         zone=$1
  33.         state=$2
  34.         steps=$3
  35.         sleep=$4
  36.         min=$5
  37.         max=$6
  38.         if [ $min -ge $max ]; then
  39.                 echo "Minimum must be lower than maximum. Exiting."
  40.                 exit 1
  41.         fi
  42.         if [ $steps -gt 0 ]; then
  43.                 licon $zone -$state $min > /dev/null
  44.                 echo "Zone:$zone Min:$min Max:$max Steps:$steps Sleep:$sleep Diff:$(($max - $min))"
  45.                 while [ $min -lt $max ]; do
  46.                         if [ $steps -ge $(($max - $min)) ]; then
  47.                                 sleep ${sleep}s
  48.                                 licon $zone -$state $max > /dev/null
  49.                                 min=$max
  50.                                 echo "Zone:$zone Min:$min Max:$max Steps:$steps Sleep:$sleep Diff:$(($max - $min))"
  51.                         else
  52.                         sleep ${sleep}s
  53.                         min=$(($min + $steps))
  54.                         echo "Zone:$zone Min:$min Max:$max Steps:$steps Sleep:$sleep Diff:$(($max - $min))"
  55.                         licon $zone -$state $min > /dev/null
  56.                         fi
  57.                 done
  58.  
  59.         elif [ $steps -lt 0 ]; then
  60.                 licon $zone -$state $max > /dev/null
  61.                 echo "Zone:$zone Min:$min Max:$max Steps:$steps Sleep:$sleep Diff:$(($max - $min))"
  62.                 while [ $max -gt $min ]; do
  63.                         if [ $steps -le $(($min - $max)) ]; then
  64.                                 sleep ${sleep}s
  65.                                 licon $zone -$state $min > /dev/null
  66.                                 max=$min
  67.                                 echo "Zone:$zone Min:$min Max:$max Steps:$steps Sleep:$sleep Diff:$(($max - $min))"
  68.                         else
  69.                         sleep ${sleep}s
  70.                         max=$(($max + $steps))
  71.                         echo "Zone:$zone Min:$min Max:$max Steps:$steps Sleep:$sleep Diff:$(($max - $min))"
  72.                         licon $zone -$state $max > /dev/null
  73.                         fi
  74.                 done
  75.  
  76.         else
  77.                 echo "Amount of steps cannot be 0. Exiting"
  78.                 exit 2
  79.         fi
  80. }
  81.  
  82. #       States: e = Temp        b = Brightness
  83. #       Zone    State   Step    Sleep   Min     Max
  84. #lux    4       $1      1.5     0       50
  85. liset   4       e       -5      .5      0       100
  86. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement