I had a similar problem. For me this interesting approach works well, using custom systemd service that periodically checks/set correct gamma level. This can also be used to maintain correct screen resolution, etc.
Also important step is to create a timer that triggers above service in periodic intervals. Service and its timer should have the same names.
There are 2 locations in which systemd services can be kept
/etc/systemd/system/ # system-wide location
/home/username/.config/systemd/user/ # user-specific location
For example create a gamma_corrector.service with below content in this folder /etc/systemd/system/
sudo nano /etc/systemd/system/gamma_corrector.service
[Unit]
Description=Gamma Level 2.0 Corrector
[Service]
Type=simple
User=username # write your username here
#ExecStart=/home/username/Desktop/gamma_corrector.sh # script can be used instead of single line command
ExecStart=/usr/bin/xrandr --output HDMI-1 --gamma 2.0:2.0:2.0 # or /usr/bin/xgamma -gamma 2.0
#Restart=always
Restart=on-failure
Environment=DISPLAY=:0 # you can check your display environment value this way echo $DISPLAY and set it here
#RemainAfterExit=yes
RemainAfterExit=no
TimeoutStartSec=10
StandardOutput=syslog
StandardError=syslog
[Install]
WantedBy=multi-user.target
create a gamma_corrector.timer to trigger above gamma correction service every 1 minute with below content in this folder /etc/systemd/system/
sudo nano /etc/systemd/system/gamma_corrector.timer
[Unit]
Description=Run Gamma Level Corrector every minute
[Timer]
OnCalendar=--* ::00 # trigger the service every minute 01:00 - 59:00, etc.
Persistent=true
OnActiveSec=1min
OnUnitActiveSec=1min
AccuracySec=1s
[Install]
WantedBy=timers.target
then run this command to make systemd incorporate this new service and its timer
sudo systemctl daemon-reload
then
xhost +SI:localuser:$(whoami) # to allow current user to access the X server:
sudo systemctl enable gamma_corrector.service
sudo systemctl enable gamma_corrector.timer
sudo systemctl start gamma_corrector.service
sudo systemctl start gamma_corrector.timer
then you can check if this gamma corrector timer works correctly and specified intervals
sudo systemctl list-timers