<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[HyperForum — [solved] Hibernation in Hyperbola (and a battery script for you!)]]></title>
	<link rel="self" href="https://forums.hyperbola.info/extern.php?action=feed&amp;tid=726&amp;type=atom" />
	<updated>2023-03-26T22:16:39Z</updated>
	<generator>PunBB</generator>
	<id>https://forums.hyperbola.info/viewtopic.php?id=726</id>
		<entry>
			<title type="html"><![CDATA[Re: [solved] Hibernation in Hyperbola (and a battery script for you!)]]></title>
			<link rel="alternate" href="https://forums.hyperbola.info/viewtopic.php?pid=5909#p5909" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>throgh wrote:</cite><blockquote><p>Hey, if you think this is ready for distribution: Would you be interested doing so? Either you choose a git-repository like notabug or codeberg. Or we can do something via Hyperbola direct, if you want.</p></blockquote></div><p>As soon as I work out the weird buggyness, sure <img src="https://forums.hyperbola.info/img/smilies/smile.png" width="15" height="15" alt="smile" /> I mean, I just feel bad inflicting this on unsuspecting users, Idk what I&#039;m doing. Would be good if an expert reviewed and patched it!</p>]]></content>
			<author>
				<name><![CDATA[auanta]]></name>
			</author>
			<updated>2023-03-26T22:16:39Z</updated>
			<id>https://forums.hyperbola.info/viewtopic.php?pid=5909#p5909</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: [solved] Hibernation in Hyperbola (and a battery script for you!)]]></title>
			<link rel="alternate" href="https://forums.hyperbola.info/viewtopic.php?pid=5905#p5905" />
			<content type="html"><![CDATA[<p>Hey, if you think this is ready for distribution: Would you be interested doing so? Either you choose a git-repository like notabug or codeberg. Or we can do something via Hyperbola direct, if you want.</p>]]></content>
			<author>
				<name><![CDATA[throgh]]></name>
				<uri>https://forums.hyperbola.info/profile.php?id=347</uri>
			</author>
			<updated>2023-03-26T12:45:38Z</updated>
			<id>https://forums.hyperbola.info/viewtopic.php?pid=5905#p5905</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: [solved] Hibernation in Hyperbola (and a battery script for you!)]]></title>
			<link rel="alternate" href="https://forums.hyperbola.info/viewtopic.php?pid=5904#p5904" />
			<content type="html"><![CDATA[<p>The only weird bug I experienced is the power button stopped triggering shutdown (equivalent to openrc-shutdown -p). The suspend on lid close also stopped working but recently started working again. All the other acpi related buttons work. </p><p>My friend and I looked over the scripts and we can&#039;t figure out why.</p><p>To some, this lack of power button responsiveness may be a bonus.</p><p>Hopefully I get better at this so I can make it perfect.</p>]]></content>
			<author>
				<name><![CDATA[auanta]]></name>
			</author>
			<updated>2023-03-26T12:20:45Z</updated>
			<id>https://forums.hyperbola.info/viewtopic.php?pid=5904#p5904</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: [solved] Hibernation in Hyperbola (and a battery script for you!)]]></title>
			<link rel="alternate" href="https://forums.hyperbola.info/viewtopic.php?pid=5813#p5813" />
			<content type="html"><![CDATA[<p>Hello everyone, </p><p>I will now mark this as <strong>solved</strong> because I figured out how to fix my script. For these scripts to work, you need to install <strong>uswsusp</strong> (to gain access to the s2disk command), <strong>wall</strong>, <strong>herbe</strong> (optional), <strong>alsa-utils</strong> (optional), and <strong>espeak</strong> (optional). And here is the final product:</p><p>1. The /etc/acpi/handler.sh has this modification:<br />At the very bottom, put:<br /></p><div class="codebox"><pre><code>. &#039;/etc/conf.d/acpi_handler.d.sh&#039;</code></pre></div><p>2. /etc/conf.d/acpi_handler.d.sh :<br /></p><div class="codebox"><pre><code>hibernate_notify () {
    # Notify when below this percentage
    low_warning=21
    # Notify when above this percentage
    high_warning=79
    # Hibernate when critically low
    crit_level=6
    # How often to check battery status, in minutes
    check_interval=5

    while true; do
      battery_level=$(acpi -b \
      | cut -d, -f2 | cut --characters=2,3,4 \
      | sed &#039;s/%//g&#039;)
    charging=$(acpi -b | grep -c &quot;Charging&quot;)

      # When battery is critically low, and not already charging
        if [ $battery_level -lt $crit_level ] &amp;&amp;
         [ $charging -eq 0 ]
        then
        wall &quot; Bateria criticamente baja: ${battery_level}% &quot; \
             &quot; Bateria tiene 5%, el sistema ya se hiberna! &quot;
        s2disk
        fi
       # When battery is low, and not already charging
        if [ $battery_level -lt $low_warning ] &amp;&amp;
         [ $charging -eq 0 ]
        then
        wall &quot; Bateria baja: ${battery_level}% &quot; \
             &quot; Bateria tiene menos que 20%, ve a recargarla! &quot;
        fi
    # When battery is high, and charging
      if [ $battery_level -gt $high_warning ] &amp;&amp;
         [ $charging -eq 1 ]
      then
        wall &quot; Bateria alta: ${battery_level}% &quot; \
             &quot; Bateria tiene mas que 80%, disconecte el cargador ahora &quot;
      fi

    sleep ${check_interval}m
    done
    unset low_warning high_warning crit_level check_interval
}

hibernate_notify</code></pre></div><p><strong>Optional: for graphical notification bubbles</strong><br />3. Put this in your .xinitrc before any exec commands:<br /></p><div class="codebox"><pre><code>. ~/battery_notify.sh &amp;</code></pre></div><p>4. Contents of battery_notify.sh :<br /></p><div class="codebox"><pre><code>#!/bin/bash

# Set the alert tone for battery, or leave it as empty quotes.
# specify path to an audio file
#alarm=&quot;&quot;

# Notify when below this percentage
low_warning=21
low_alarm=&quot;&quot;
low_repeat=1

# Notify when above this percentage
high_warning=79
high_alarm=&quot;&quot;
high_repeat=5

while true; do
  battery_level=$(acpi -b \
    | cut -d, -f2 | cut --characters=2,3,4 \
    | sed &#039;s/%//g&#039;)
  charging=$(acpi -b | grep -c &quot;Charging&quot;)
  sleep 1m

    # When battery is low, and not already charging
    if [ $battery_level -lt $low_warning ] &amp;&amp;
       [ $charging -eq 0 ]
    then
      #play -q -v 0.40 &quot;$low_alarm&quot; &amp;
      #espeak &quot;blablabla&quot; -s 140
      herbe &quot;Batteria baja: ${battery_level}% &quot; \
            &quot; Bateria no tiene carga suficiente, ve a recargarla ahora para protegerla. &quot;
       sleep ${low_repeat}m
      fi

    # When battery is high, and charging
     if [ $battery_level -gt $high_warning ] &amp;&amp;
        [ $charging -eq 1 ]
     then
      #play -q -v 0.40 &quot;$alarm&quot; &amp;
      #espeak &quot;blablabla&quot; - s 140
      herbe &quot; Batteria alta: ${battery_level}% &quot; \
      &quot; Bateria ya esta llena, disconecte el cargador ahora para protejerla.&quot;
       sleep ${high_repeat}m
      fi
done</code></pre></div><p>I am very satisfied with its outcome and I hope that others will consider using it.</p>]]></content>
			<author>
				<name><![CDATA[auanta]]></name>
			</author>
			<updated>2023-03-06T19:32:55Z</updated>
			<id>https://forums.hyperbola.info/viewtopic.php?pid=5813#p5813</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: [solved] Hibernation in Hyperbola (and a battery script for you!)]]></title>
			<link rel="alternate" href="https://forums.hyperbola.info/viewtopic.php?pid=5808#p5808" />
			<content type="html"><![CDATA[<p>(Mods if youre reading this, you can leave this up)</p><p>OK, I have updated my script once again. </p><p>This time, instead of including my modifications in /etc/acpi/handler.sh I invoke my script by calling it in a separate file.</p><div class="codebox"><pre><code>#!/bin/sh
# default acpi script that takes an entry for all actions.

. &#039;/etc/conf.d/acpid&#039;
. &#039;/etc/conf.d/acpi_handler.d.sh&#039;</code></pre></div><p>In my debugging process I learned that ny efforts to nest the script cause it to be useless, so I removed the nesting. Contents of /etc/conf.d/acpi_handler.d.sh :</p><div class="codebox"><pre><code>    # Notify when below this percentage
    low_warning=21
    # Notify when above this percentage
    high_warning=79
    # Hibernate when critically low
    crit_level=6
    # How often to check battery status, in minutes
    check_interval=5

    while true; do
      battery_level=$(acpi -b \
      | cut -d, -f2 | cut --characters=2,3,4 \
      | sed &#039;s/%//g&#039;)
    charging=$(acpi -b | grep -c &quot;Charging&quot;)

      # When battery is critically low, and not already charging
        if [ $battery_level -lt $crit_level ] &amp;&amp;
         [ $charging -eq 0 ]
        then
        wall &quot; Bateria criticamente baja: ${battery_level}% &quot; \
             &quot; Bateria tiene 5%, el sistema ya se hiberna! &quot;
        s2disk
        fi
       # When battery is low, and not already charging
        if [ $battery_level -lt $low_warning ] &amp;&amp;
         [ $charging -eq 0 ]
        then
        wall &quot; Bateria baja: ${battery_level}% &quot; \
             &quot; Bateria tiene menos que 20%, ve a recargarla! &quot;
        fi
    # When battery is high, and charging
      if [ $battery_level -gt $high_warning ] &amp;&amp;
         [ $charging -eq 1 ]
      then
        wall &quot; Bateria alta: ${battery_level}% &quot; \
             &quot; Bateria tiene mas que 80%, disconecte el cargador ahora &quot;
      fi

    sleep ${check_interval}m
    done
    unset low_warning high_warning crit_level check_interval</code></pre></div><p>However, now the power button does not work again, I have still broken the handler.sh so I think I need to nest my script and find a way to invoke it while making it play nice with handler.sh</p><p>Now for <strong>the good news: I set up graphical pop-up reminders, and optional sound notifications by launching a second separate, non-root script from .xinitrc</strong>. This is useful when your terminal does not support such things as utmp or you just want the animated, ephemeral pop up notifications. Here is the script you can use:</p><div class="codebox"><pre><code>#!/bin/bash

# Set the alert tone for battery, or leave it as empty quotes.
# choose an audio file
#alarm=&quot;&quot;

# Notify when below this percentage
low_warning=21

# Notify when above this percentage
high_warning=79

while true; do
  battery_level=$(acpi -b \
    | cut -d, -f2 | cut --characters=2,3,4 \
    | sed &#039;s/%//g&#039;)
  charging=$(acpi -b | grep -c &quot;Charging&quot;)
  sleep 1m

    # When battery is low, and not already charging
    if [ $battery_level -lt $low_warning ] &amp;&amp;
       [ $charging -eq 0 ]
    then
      #play -q -v 0.40 &quot;$alarm&quot; &amp;
      #espeak &quot;blablabla&quot; -s 140
      herbe &quot;Batteria baja: ${battery_level}% &quot; \
            &quot; Bateria no tiene carga suficiente, ve a recargarla ahora para protegerla. &quot;
       sleep 1m
      fi

    # When battery is high, and charging
     if [ $battery_level -gt $high_warning ] &amp;&amp;
        [ $charging -eq 1 ]
     then
      #play -q -v 0.40 &quot;$alarm&quot; &amp;
      #espeak &quot;blablabla&quot; - s 140
      herbe &quot; Batteria alta: ${battery_level}% &quot; \
      &quot; Bateria ya esta llena, disconecte el cargador ahora para protegerla.&quot;
       sleep 5m
      fi
done</code></pre></div><p>Then just set up your .xinitrc:</p><div class="codebox"><pre><code>light -S 5 &amp;
. /home/you/yourscripts/battery_notify.sh &amp;
redshift &amp;
exec cwm</code></pre></div><p>The script definitely works well, no apparent bugs that I found, but when it comes to harmonious coexistence between handler.sh and handler.d.sh, I can&#039;t yet get handler.d.sh to stop disabling some of the handler.sh functionality.</p>]]></content>
			<author>
				<name><![CDATA[auanta]]></name>
			</author>
			<updated>2023-03-05T18:43:54Z</updated>
			<id>https://forums.hyperbola.info/viewtopic.php?pid=5808#p5808</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: [solved] Hibernation in Hyperbola (and a battery script for you!)]]></title>
			<link rel="alternate" href="https://forums.hyperbola.info/viewtopic.php?pid=5807#p5807" />
			<content type="html"><![CDATA[<p>I have updated the script so that this portion is nested:</p><div class="codebox"><pre><code>acpi_battery() {

    # Notify when below this percentage
    low_warning=21
    # Notify when above this percentage
    high_warning=79
    # Hibernate when critically low
    crit_level=6
    # How often to check battery status, in minutes
    check_interval=5

    while true; do
      battery_level=$(acpi -b \
      | cut -d, -f2 | cut --characters=2,3,4 \
      | sed &#039;s/%//g&#039;)
    charging=$(acpi -b | grep -c &quot;Charging&quot;)

      # When battery is critically low, and not already charging
        if [ $battery_level -lt $crit_level ] &amp;&amp;
         [ $charging -eq 0 ]
        then
        wall &quot; Bateria criticamente baja: ${battery_level}% &quot; \
             &quot; Bateria tiene 5%, el sistema ya se hiberna! &quot;
        s2disk
        fi
       # When battery is low, and not already charging
        if [ $battery_level -lt $low_warning ] &amp;&amp;
         [ $charging -eq 0 ]
        then
        wall &quot; Bateria baja: ${battery_level}% &quot; \
             &quot; Bateria tiene menos que 20%, ve a recargarla! &quot;
         sleep 1
        fi
    # When battery is high, and charging
      if [ $battery_level -gt $high_warning ] &amp;&amp;
         [ $charging -eq 1 ]
      then
        wall &quot; Bateria alta: ${battery_level}% &quot; \
             &quot; Bateria tiene mas que 80%, disconecte el cargador ahora &quot;
         sleep 1
      fi

    sleep ${check_interval}
    done
    unset low_warning high_warning crit_level check_interval
    }</code></pre></div><p>Now I do not have anymore weird problems like that.</p><p>However, now my script is not being called, I guess, as it does not work.</p>]]></content>
			<author>
				<name><![CDATA[auanta]]></name>
			</author>
			<updated>2023-03-05T18:42:29Z</updated>
			<id>https://forums.hyperbola.info/viewtopic.php?pid=5807#p5807</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: [solved] Hibernation in Hyperbola (and a battery script for you!)]]></title>
			<link rel="alternate" href="https://forums.hyperbola.info/viewtopic.php?pid=5806#p5806" />
			<content type="html"><![CDATA[<p>Hello! So I now understand that the /etc/acpi/handler.sh script is a Bourne shell script and it is compatible with my Bash script, but I am having weird problems when I add my modifications to the script directly. The power button stops working, for example. The weirdness stops when I remove my modifications. Here is my script:</p><div class="codebox"><pre><code>#!/bin/sh
# default acpi script that takes an entry for all actions.

. &#039;/etc/conf.d/acpid&#039;

# check OS name with HyperbolaBSD uname.
UNAME=&quot;$(uname -s)&quot;

acpid_ac_adapter() {
  case &quot;${1}&quot; in
  &#039;plug&#039;)
    LAD=&quot;${ACPID_AP}&quot;
    ;;
  &#039;unplug&#039;)
    LAD=&quot;${ACPID_AU}&quot;
    ;;
  *)
    return
    ;;
  esac

  case &quot;${UNAME}&quot; in
  &#039;Linux&#039;)
    LFD=&quot;/sys/class/backlight/${ACPID_AB}&quot;
    LBF=&quot;${LFD}/brightness&quot;
    LMF=&quot;${LFD}/max_brightness&quot;
    unset LFD
    printf &quot;$((${LAD}*$(su -c &#039;cat &#039;${LMF})/100))&quot; &gt; &quot;${LBF}&quot;
    unset LBF LMF
    ;;
  &#039;HyperbolaBSD&#039;|*)
    return
    ;;
  esac

  unset LAD
}

acpid_echo_sound() {
  _play_audio() {
    case &quot;${1}&quot; in
    &#039;sndio&#039;)
      LSS=&quot;${1}&quot;
      LSF=&quot;snd/${ACPID_SC}&quot;
      ;;
    *)
      case &quot;${UNAME}&quot; in
      &#039;Linux&#039;)
        LSS=&#039;alsa&#039;
        LSF=&quot;hw:${ACPID_SC}&quot;
        ;;
      &#039;HyperbolaBSD&#039;|*)
        LSS=&#039;oss&#039;
        LSF=&quot;/dev/dsp${ACPID_SC}&quot;
        ;;
      esac
      ;;
    esac

    LFD=&#039;/usr/share/sounds/freedesktop/stereo&#039;
    LFF=&quot;${LFD}/audio-volume-change.oga&quot;
    unset LFD

    if [ -x &#039;/usr/bin/ffmpeg&#039; ] &amp;&amp; [ -f &quot;${LFF}&quot; ]; then
      LXC=&#039;-loglevel -8&#039;
      ffmpeg &quot;${LXC}&quot; -i &quot;${LFF}&quot; -f &quot;${LSS}&quot; &quot;${LSF}&quot;
      unset LXC
    fi

    unset LDF LFF LSF LSS
  }

  _cksrv_and_play_audio() {
    case &quot;${1}&quot; in
    &#039;openrc&#039;)
      LSC=&#039;rc-service sndiod status&#039;
      ;;
    &#039;runit&#039;)
      LSC=&#039;sv status sndiod&#039;
      ;;
    esac

    case &quot;$(${LSC})&quot; in
    &#039; * status: started&#039;|&#039;run: sndio&#039;)
      _play_audio &#039;sndio&#039;
      ;;
    *)
      _play_audio
      ;;
    esac

    unset LSC
  }

  if [ -x &#039;/sbin/rc-service&#039; ]; then
    _cksrv_and_play_audio &#039;openrc&#039;
  elif [ -x &#039;/usr/bin/sv&#039; ]; then
    _cksrv_and_play_audio &#039;runit&#039;
  fi
}

acpid_video_brightness() {
  case &quot;${1}&quot; in
  &#039;up&#039;)
    LCB=&#039;+&#039;
    ;;
  &#039;down&#039;)
    LCB=&#039;-&#039;
    ;;
  *)
    return
    ;;
  esac

  case &quot;${UNAME}&quot; in
  &#039;Linux&#039;)
    LFD=&quot;/sys/class/backlight/${ACPID_AB}&quot;
    LBF=&quot;${LFD}/brightness&quot;
    LMF=&quot;${LFD}/max_brightness&quot;
    unset LFD
    printf &quot;$((${ACPID_BP}*$(su -c &#039;cat &#039;${LMF})/100 ${LCB} $(cat ${LBF})))&quot; \
      &gt; &quot;${LBF}&quot;
    unset LBF LMF
    ;;
  &#039;HyperbolaBSD&#039;|*)
    return
    ;;
  esac

  unset LCB
}

case &quot;${1}&quot; in
&#039;ac_adapter&#039;)
  case &quot;${2}&quot; in
  &#039;AC&#039;|&#039;ACAD&#039;|&#039;ACPI&#039;????&#039;:&#039;??|&#039;ADP&#039;?)
    case &quot;${4}&quot; in
    &#039;00000000&#039;)
      # ac pluged
      acpid_ac_adapter &#039;plug&#039;
      ;;
    &#039;00000001&#039;)
      # ac unpluged
      acpid_ac_adapter &#039;unplug&#039;
      ;;
    esac
    ;;
  esac
  ;;
&#039;battery&#039;)
  case &quot;${2}&quot; in
  &#039;BAT&#039;?|&#039;PNP&#039;?&#039;C&#039;??)
    case &quot;${4}&quot; in
    &#039;00000000&#039;)
      # battery online
      ;;
    &#039;00000001&#039;)
      # battery offline
      ;;
    esac
    ;;
  esac
  ;;
&#039;button/lid&#039;)
  case &quot;${3}&quot; in
  &#039;close&#039;)
    case &quot;${UNAME}&quot; in
    &#039;Linux&#039;)
      printf &quot;${ACPID_ST}&quot; &gt; &#039;/sys/power/state&#039;
      ;;
    esac
    ;;
  &#039;open&#039;)
    ;;
  esac
  ;;
&#039;button/mute&#039;)
  case &quot;${2}&quot; in
  &#039;MUTE&#039;)
    case &quot;${UNAME}&quot; in
    &#039;Linux&#039;)
      if [ -x &#039;/usr/bin/amixer&#039; ]; then
        amixer -c &quot;${ACPID_SC}&quot; set &#039;Master&#039; toggle
      fi
      acpid_echo_sound
      ;;
    #&#039;HyperbolaBSD&#039;|*)
    #  if [ -x &#039;/usr/bin/sndioctl&#039; ]; then
    #    sndioctl -nq snd/${ACPID_SC}.mute=&#039;off&#039;
    #  elif [ -x &#039;/usr/sbin/mixerctl&#039; ]; then
    #    mixerctl -qf &quot;/dev/audioctl${ACPID_SC}&quot; output.dac.mute=&#039;off&#039;
    #  fi
    #  acpid_echo_sound
    #  ;;
    esac
    ;;
  esac
  ;;
&#039;button/power&#039;)
  case &quot;${2}&quot; in
  &#039;PBTN&#039;|&#039;PWRF&#039;)
    if [ -x &#039;/sbin/openrc-shutdown&#039; ]; then
      openrc-shutdown -p
    else
      poweroff -p
    fi
    ;;
  esac
  ;;
&#039;button/sleep&#039;)
  case &quot;${2}&quot; in
  &#039;SBTN&#039;|&#039;SLPB&#039;)
    case &quot;${UNAME}&quot; in
    &#039;Linux&#039;)
      printf &quot;${ACPID_ST}&quot; &gt; &#039;/sys/power/state&#039;
      ;;
    esac
    ;;
  esac
  ;;
&#039;button/volumedown&#039;)
  case &quot;${2}&quot; in
  &#039;VOLDN&#039;)
    case &quot;${UNAME}&quot; in
    &#039;Linux&#039;)
      if [ -x &#039;/usr/bin/amixer&#039; ]; then
        amixer -c &quot;${ACPID_SC}&quot; set &#039;Master&#039; &quot;${ACPID_SP}%-&quot;
      fi
        acpid_echo_sound
      ;;
    #&#039;HyperbolaBSD&#039;|*)
    #  if [ -x &#039;/usr/bin/sndioctl&#039; ]; then
    #    sndioctl -nq snd/${ACPID_SC}.level-=&quot;${ACPID_SP}&quot;
    #  elif [ -x &#039;/usr/sbin/mixerctl&#039; ]; then
    #    mixerctl -qf &quot;/dev/audioctl${ACPID_SC}&quot; \
    #      output.dac.level-=&quot;${ACPID_SP}&quot;
    #  fi
    #  acpid_echo_sound
    #  ;;
    esac
    ;;
  esac
  ;;
&#039;button/volumeup&#039;)
  case &quot;${2}&quot; in
  &#039;VOLUP&#039;)
    case &quot;$(uname -s)&quot; in
    &#039;Linux&#039;)
      if [ -x &#039;/usr/bin/amixer&#039; ]; then
        amixer -c &quot;${ACPID_SC}&quot; set &#039;Master&#039; &quot;${ACPID_SP}%+&quot;
      fi
      acpid_echo_sound
      ;;
    #&#039;HyperbolaBSD&#039;|*)
    #  if [ -x &#039;/usr/bin/sndioctl&#039; ]; then
    #    sndioctl -nq snd/${ACPID_SC}.level+=&quot;${ACPID_SP}&quot;
    #  elif [ -x &#039;/usr/sbin/mixerctl&#039; ]; then
    #    mixerctl -qf &quot;/dev/audioctl${ACPID_SC}&quot; \
    #      output.dac.level+=&quot;${ACPID_SP}&quot;
    #  fi
    #  acpid_echo_sound
    #  ;;
    esac
    ;;
  esac
  ;;
&#039;jack/headphone&#039;)
  case &quot;${2}&quot; in
  &#039;HEADPHONE&#039;)
    case &quot;${3}&quot; in
    &#039;plug&#039;)
      ;;
    &#039;unplug&#039;)
      ;;
    esac
    ;;
  esac
  ;;
&#039;video/brightnessdown&#039;)
  case &quot;${2}&quot; in
  &#039;BRTDN&#039;)
    acpid_video_brightness &#039;down&#039;
    ;;
  esac
  ;;
&#039;video/brightnessup&#039;)
  case &quot;${2}&quot; in
  &#039;BRTUP&#039;)
    acpid_video_brightness &#039;up&#039;
    ;;
  esac
  ;;
&#039;video/switchmode&#039;)
  case &quot;${2}&quot; in
  &#039;VMOD&#039;)
    ;;
  esac
  ;;
&#039;cd/next&#039;)
  case &quot;${2}&quot; in
  &#039;CDNEXT&#039;)
    ;;
  esac
  ;;
&#039;cd/play&#039;)
  case &quot;${2}&quot; in
  &#039;CDPLAY&#039;)
    # It is disabled, because it is not supported with multimedia keys and
    # it was not tested.
    #if [ -x &#039;/usr/bin/mpv&#039; ]; then
    #  mpv &#039;cdda://:1&#039; -cache &#039;1024&#039;
    #elif [ -x &#039;/usr/bin/mplayer&#039; ]; then
    #  mplayer &#039;cdda://:1&#039; -cache &#039;1024&#039;
    #fi
    ;;
  esac
  ;;
&#039;cd/prev&#039;)
  case &quot;${2}&quot; in
  &#039;CDPREV&#039;)
    ;;
  esac
  ;;
&#039;cd/stop&#039;)
  case &quot;${2}&quot; in
  &#039;CDSTOP&#039;)
    ;;
  esac
  ;;
esac

# Modified from: https://gist.github.com/bandaangosta/0a0fdbd03215b925576c4b234fc4d4f1
# Credits to user BlackVeils and bandaangosta

# Notify when below this percentage
low_warning=21

# Notify when above this percentage
high_warning=79

# Hibernate when critically low
crit_level=6

# How often to check battery status, in minutes
check_interval=5

while true; do
  battery_level=$(acpi -b \
    | cut -d, -f2 | cut --characters=2,3,4 \
    | sed &#039;s/%//g&#039;)
  charging=$(acpi -b | grep -c &quot;Charging&quot;)

  # When battery is critically low, and not already charging
  if [ $battery_level -lt $crit_level ] &amp;&amp;
     [ $charging -eq 0 ]
  then
    wall &quot; Bateria criticamente baja: ${battery_level}% &quot; \
      &quot; Bateria tiene 5%, el sistema ya se hiberna! &quot;
    s2disk
  fi

  # When battery is low, and not already charging
  if [ $battery_level -lt $low_warning ] &amp;&amp;
     [ $charging -eq 0 ]
  then
   wall &quot; Bateria baja: ${battery_level}% &quot; \
      &quot; Bateria tiene menos que 20%, ve a recargarla! &quot;
   sleep 1
  fi

# When battery is high, and charging
  if [ $battery_level -gt $high_warning ] &amp;&amp;
     [ $charging -eq 1 ]
  then
    wall &quot; Bateria alta: ${battery_level}% &quot; \
      &quot; Bateria tiene mas que 80%, disconecte el cargador ahora &quot;
    sleep 1
  fi
  
  sleep ${check_interval}
done</code></pre></div>]]></content>
			<author>
				<name><![CDATA[auanta]]></name>
			</author>
			<updated>2023-03-05T16:32:56Z</updated>
			<id>https://forums.hyperbola.info/viewtopic.php?pid=5806#p5806</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: [solved] Hibernation in Hyperbola (and a battery script for you!)]]></title>
			<link rel="alternate" href="https://forums.hyperbola.info/viewtopic.php?pid=5778#p5778" />
			<content type="html"><![CDATA[<p>Hello! I waited for the release of zzz and tried it out. The default behavior I am seeing, contrary to the manpage, is it causes the computer to suspend but not hibernate.</p><p>When I doas zzz -Z to force it to hibernate, it looks as if it does but when I turn the computer on, it shows on bootup that the ext4 filesystem is repairing the journal, and my previous session&#039;s commands in bash are unsaved. This is what typically happens when my computer runs out of power and shutdown improperly.</p><p>OK I am trying uswsusp..How do I rebuild the ramdisk? Oh, simply reinstall linux:</p><p>pacman -S linux<br /></p><div class="codebox"><pre><code>(1/1) reinstalling linux-libre-lts                                                                            [#################################################################] 100%
&gt;&gt;&gt; Updating module dependencies. Please wait ...
:: Running post-transaction hooks...
(1/2) Updating module dependencies...
(2/2) Updating linux-libre-lts initcpios
==&gt; Building image from preset: /etc/mkinitcpio.d/linux-libre-lts.preset: &#039;default&#039;
  -&gt; -k /boot/vmlinuz-linux-libre-lts -c /etc/mkinitcpio.conf -g /boot/initramfs-linux-libre-lts.img
==&gt; Starting build: 5.10.127-gnu1-1-lts
  -&gt; Running build hook: [base]
  -&gt; Running build hook: [udev]
  -&gt; Running build hook: [autodetect]
  -&gt; Running build hook: [modconf]
  -&gt; Running build hook: [block]
  -&gt; Running build hook: [uresume]
  -&gt; Running build hook: [filesystems]
  -&gt; Running build hook: [keyboard]
  -&gt; Running build hook: [fsck]
==&gt; Generating module dependencies
==&gt; Creating xz-compressed initcpio image: /boot/initramfs-linux-libre-lts-fallback.img
==&gt; Image generation successful</code></pre></div><p>Sure took a while to finish generating...but it did!</p><p>$ doas s2disk</p><p>OMG! It hibernated successfully!</p><p>Would it be possible for me to change /etc/acpi/handler.sh to hibernate at 5%? Would uswsusp&#039;s s2disk therefore be the command in this acpi handler script?</p><div class="codebox"><pre><code>&#039;button/power&#039;)
  case &quot;${2}&quot; in
  &#039;PBTN&#039;|&#039;PWRF&#039;)
    if [ -x &#039;/sbin/openrc-shutdown&#039; ]; then
      openrc-shutdown -p
    else
      poweroff -p
    fi
    ;;
  esac
  ;;</code></pre></div><div class="codebox"><pre><code>&#039;battery&#039;)
  case &quot;${2}&quot; in
  &#039;BAT&#039;?|&#039;PNP&#039;?&#039;C&#039;??)
    case &quot;${4}&quot; in
    &#039;00000000&#039;)
      # battery online
      ;;
    &#039;00000001&#039;)
      # battery offline
      ;;
    esac
    ;;
  esac
  ;;</code></pre></div><div class="codebox"><pre><code>&#039;button/sleep&#039;)
  case &quot;${2}&quot; in
  &#039;SBTN&#039;|&#039;SLPB&#039;)
    case &quot;${UNAME}&quot; in
    &#039;Linux&#039;)
      printf &quot;${ACPID_ST}&quot; &gt; &#039;/sys/power/state&#039;
      ;;
    esac
    ;;
  esac
  ;;</code></pre></div><p>I have to figure out how to make my own hibernate lines.<br />Maybe this? <a href="https://github.com/thcipriani/acpi/blob/master/handler.sh">https://github.com/thcipriani/acpi/blob … handler.sh</a><br /><a href="https://gist.github.com/nk23x/7600782">https://gist.github.com/nk23x/7600782</a></p><p>Meanwhile, I modified the userspace bash script to hibernate when battery is below 6%. I need to figure out how to <strong>make it run at boot with rc-update</strong> but the world&#039;s search engines all appear to be broken. :?</p><div class="codebox"><pre><code>#!/bin/bash

# Modified from: https://gist.github.com/bandaangosta/0a0fdbd03215b925576c4b234fc4d4f1
# Credits to user BlackVeils and bandaangosta

# Steps:
# 1. Save this script to battery_notify.sh
# 2. Edit the &#039;alarm&#039; variable to point to your sound file of choice
# 3. Give execution permission: chmod +x battery_notify.sh
# 4. Run the script to test it. If happy, add to your startup applications.

# Set the alert tone for battery, or leave it as empty quotes.
# choose an audio file
alarm=&quot;&quot;

# Notify when below this percentage
low_warning=21

# Notify when above this percentage
high_warning=79

# Hibernate when critically low
crit_level=6

# How often to check battery status, in minutes
check_interval=5

while true; do
  battery_level=$(acpi -b \
    | cut -d, -f2 | cut --characters=2,3,4 \
    | sed &#039;s/%//g&#039;)
  charging=$(acpi -b | grep -c &quot;Charging&quot;)

  # When battery is critically low, and not already charging
  if [ $battery_level -lt $crit_level ] &amp;&amp;
     [ $charging -eq 0 ]
  then
#    play -q -v 0.40 &quot;$alarm&quot; &amp;
# espeak &quot;Atencion, la bateria ya tiene 20%, por favor conecte el cargador&quot; -s 140
    herbe &quot; Low battery: ${battery_level}% &quot; \
      &quot; Bateria tiene 5%, el sistema ya se hiberna! &quot;
    s2disk
  fi

  # When battery is low, and not already charging
  if [ $battery_level -lt $low_warning ] &amp;&amp;
     [ $charging -eq 0 ]
  then
#    play -q -v 0.40 &quot;$alarm&quot; &amp;
# espeak &quot;Atencion, la bateria ya tiene 20%, por favor conecte el cargador&quot; -s 140
    herbe &quot; Low battery: ${battery_level}% &quot; \
      &quot; Bateria tiene 20%, ve a recargarlo! &quot;
  fi

# When battery is high, and charging
  if [ $battery_level -gt $high_warning ] &amp;&amp;
     [ $charging -eq 1 ]
  then
#    play -q -v 0.40 &quot;$alarm&quot; &amp;
# espeak &quot;Atencion, la bateria ya tiene 80%, por favor quite el cargador&quot; - s 140
    herbe &quot; High battery: ${battery_level}% &quot; \
      &quot; Bateria tiene 80%, disconecte el cargador ahora &quot;
  fi
  
  sleep ${check_interval}
done</code></pre></div>]]></content>
			<author>
				<name><![CDATA[auanta]]></name>
			</author>
			<updated>2023-02-28T23:04:53Z</updated>
			<id>https://forums.hyperbola.info/viewtopic.php?pid=5778#p5778</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: [solved] Hibernation in Hyperbola (and a battery script for you!)]]></title>
			<link rel="alternate" href="https://forums.hyperbola.info/viewtopic.php?pid=5175#p5175" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>throgh wrote:</cite><blockquote><p>Yes, <strong>zzz</strong> can be used alone. And changing the mac-address is also possible: <a href="https://www.hyperbola.info/packages/?sort=&amp;q=macchanger&amp;maintainer=&amp;flagged=">https://www.hyperbola.info/packages/?so … p;flagged=</a></p><p>About ISO for HyperbolaBSD: Not yet as we are working on the kernel.</p></blockquote></div><p>As well as the package manager and similar stuff, right? Aka, for HyperbolaBSD...</p><p>Aka, its more than just the kernel that needs to worked on, right?</p><p>Didn&#039;t tpad-tools do this randomly anytime you connected to the internet via x200? </p><p>Although, couldn&#039;t figure out how to get the backup/thinkvantage functions to work on it yet either. :s</p><p>Either way, I am willing to bet you are close to both alpha and beta, given the team has been working on parts of both at the same time.</p><p>Watching with interest though when&nbsp; I can though! <img src="https://forums.hyperbola.info/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></content>
			<author>
				<name><![CDATA[zapper]]></name>
				<uri>https://forums.hyperbola.info/profile.php?id=117</uri>
			</author>
			<updated>2022-11-06T11:51:35Z</updated>
			<id>https://forums.hyperbola.info/viewtopic.php?pid=5175#p5175</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: [solved] Hibernation in Hyperbola (and a battery script for you!)]]></title>
			<link rel="alternate" href="https://forums.hyperbola.info/viewtopic.php?pid=5173#p5173" />
			<content type="html"><![CDATA[<p>Yes, <strong>zzz</strong> can be used alone. And changing the mac-address is also possible: <a href="https://www.hyperbola.info/packages/?sort=&amp;q=macchanger&amp;maintainer=&amp;flagged=">https://www.hyperbola.info/packages/?so … p;flagged=</a></p><p>About ISO for HyperbolaBSD: Not yet as we are working on the kernel.</p>]]></content>
			<author>
				<name><![CDATA[throgh]]></name>
				<uri>https://forums.hyperbola.info/profile.php?id=347</uri>
			</author>
			<updated>2022-11-06T10:18:16Z</updated>
			<id>https://forums.hyperbola.info/viewtopic.php?pid=5173#p5173</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: [solved] Hibernation in Hyperbola (and a battery script for you!)]]></title>
			<link rel="alternate" href="https://forums.hyperbola.info/viewtopic.php?pid=5167#p5167" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>throgh wrote:</cite><blockquote><p>Oh, the package &quot;zzz&quot; can be used completely without runit. I&#039;m using it here since weeks on a test-installation. More in details:</p><p>fluxbox<br />tint3 (with common additions)<br />spacefm<br />zzz (for suspend)</p><p>Before leaving that out: Sure, you need to add the command within <strong>/etc/doas.conf</strong> as &quot;/usr/sbin/zzz&quot; to execute without password. After that: You are free to do, also with OpenRC. And ... perhaps others to come. But that&#039;s quite to early to say as testing is early into this. Runit and OpenRC are the stable ones within our system for the moment, with the thoughts for HyperbolaBSD also.</p></blockquote></div><p>That is good news at least.</p><p>Btw, I noticed there&nbsp; was a low power mode option, what does this do in Hyperbola? Is it like hibernate, or something else?</p><p>Just curious...</p><p>zzz seems to work fine tho. <img src="https://forums.hyperbola.info/img/smilies/smile.png" width="15" height="15" alt="smile" /></p><p>zzz can be used without runit?</p><p>I always get the conflict issue... very strange...</p><p>tpad-tools is the only other interest, but no worries...</p><p>I suppose I might&nbsp; not need it anyhow...</p><p>I will miss though that one function of random mac address.</p><p><img src="https://forums.hyperbola.info/img/smilies/tongue.png" width="15" height="15" alt="tongue" /></p><p>HyperbolaBSD doesn&#039;t have any alpha isos yet right?</p><p>If there is, you may want to distribute as qcow2 images if anyone has interest in testing... and not the iso itself!</p><p>Just a thought till it is at beta stability...</p><p>Although maybe not, just again... a thought.</p>]]></content>
			<author>
				<name><![CDATA[zapper]]></name>
				<uri>https://forums.hyperbola.info/profile.php?id=117</uri>
			</author>
			<updated>2022-11-06T04:07:06Z</updated>
			<id>https://forums.hyperbola.info/viewtopic.php?pid=5167#p5167</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: [solved] Hibernation in Hyperbola (and a battery script for you!)]]></title>
			<link rel="alternate" href="https://forums.hyperbola.info/viewtopic.php?pid=5159#p5159" />
			<content type="html"><![CDATA[<p>Oh, the package &quot;zzz&quot; can be used completely without runit. I&#039;m using it here since weeks on a test-installation. More in details:</p><p>fluxbox<br />tint3 (with common additions)<br />spacefm<br />zzz (for suspend)</p><p>Before leaving that out: Sure, you need to add the command within <strong>/etc/doas.conf</strong> as &quot;/usr/sbin/zzz&quot; to execute without password. After that: You are free to do, also with OpenRC. And ... perhaps others to come. But that&#039;s quite to early to say as testing is early into this. Runit and OpenRC are the stable ones within our system for the moment, with the thoughts for HyperbolaBSD also.</p>]]></content>
			<author>
				<name><![CDATA[throgh]]></name>
				<uri>https://forums.hyperbola.info/profile.php?id=347</uri>
			</author>
			<updated>2022-11-04T13:52:24Z</updated>
			<id>https://forums.hyperbola.info/viewtopic.php?pid=5159#p5159</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: [solved] Hibernation in Hyperbola (and a battery script for you!)]]></title>
			<link rel="alternate" href="https://forums.hyperbola.info/viewtopic.php?pid=5156#p5156" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>throgh wrote:</cite><blockquote><p>You can also use <a href="https://www.hyperbola.info/packages/?sort=&amp;q=zzz&amp;maintainer=&amp;flagged=">zzz</a> being part of testing and coming with the release 0.4.2. <img src="https://forums.hyperbola.info/img/smilies/smile.png" width="15" height="15" alt="smile" /></p></blockquote></div><p>With or without runit?</p><p><img src="https://forums.hyperbola.info/img/smilies/wink.png" width="15" height="15" alt="wink" /></p><p>If it is without it, I could starting using it on my non libreboot x200 devices and potentially more, without conflict between tpad-tools.</p><p>Btw,&nbsp; thank you all for what you do for the free software community.</p><p>I haven&#039;t said this for a while, due to not wanting to appear, to be, bribing/playing up to you all, but yeah, I very much mean it.</p><p><img src="https://forums.hyperbola.info/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></content>
			<author>
				<name><![CDATA[zapper]]></name>
				<uri>https://forums.hyperbola.info/profile.php?id=117</uri>
			</author>
			<updated>2022-11-04T13:32:08Z</updated>
			<id>https://forums.hyperbola.info/viewtopic.php?pid=5156#p5156</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: [solved] Hibernation in Hyperbola (and a battery script for you!)]]></title>
			<link rel="alternate" href="https://forums.hyperbola.info/viewtopic.php?pid=5151#p5151" />
			<content type="html"><![CDATA[<p>You can also use <a href="https://www.hyperbola.info/packages/?sort=&amp;q=zzz&amp;maintainer=&amp;flagged=">zzz</a> being part of testing and coming with the release 0.4.2. <img src="https://forums.hyperbola.info/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></content>
			<author>
				<name><![CDATA[throgh]]></name>
				<uri>https://forums.hyperbola.info/profile.php?id=347</uri>
			</author>
			<updated>2022-11-04T10:04:34Z</updated>
			<id>https://forums.hyperbola.info/viewtopic.php?pid=5151#p5151</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: [solved] Hibernation in Hyperbola (and a battery script for you!)]]></title>
			<link rel="alternate" href="https://forums.hyperbola.info/viewtopic.php?pid=4978#p4978" />
			<content type="html"><![CDATA[<p>Yes: You can use <a href="https://www.hyperbola.info/packages/?sort=&amp;q=uswsusp&amp;maintainer=&amp;flagged=">uswsusp</a> for this. Here more information about that kernel-module also: <a href="https://wiki.archlinux.org/title/Uswsusp">https://wiki.archlinux.org/title/Uswsusp</a></p>]]></content>
			<author>
				<name><![CDATA[throgh]]></name>
				<uri>https://forums.hyperbola.info/profile.php?id=347</uri>
			</author>
			<updated>2022-09-08T18:00:39Z</updated>
			<id>https://forums.hyperbola.info/viewtopic.php?pid=4978#p4978</id>
		</entry>
</feed>
