Scripted Cover/Window/Blinds Timed Fake State

Just sharing this solution.

The Commandline Cover, sets the cover (Somfy/RFLinkGW) and starts a script.

cover:
  - platform: command_line
    covers:
      main_cover:
        friendly_name: Shield
        command_open: "echo -e '10;RTS;646566;1;UP;' > /dev/ttyACM0 ; /volume1/homeassistant/states.sh U"
        command_close: "echo -e '10;RTS;646566;1;DOWN;' > /dev/ttyACM0 ; /volume1/homeassistant/states.sh D"
        command_stop: "echo -e '10;RTS;646566;1;STOP;' > /dev/ttyACM0 ; /volume1/homeassistant/states.sh S"
        command_state: "cat /volume1/homeassistant/coverstate.state"

The first script spawns a named screen session with the second script and detaches. If one already exists, it’s terminated.

states.sh:

screen -S HassCoverScreen -X quit ; screen -S HassCoverScreen -dm /volume1/homeassistant/statescount.sh $1 ; exit 0

The second script counts up or down to a file thats contains the state 0-100. As my cover takes 24 seconds to fully close or open, the script adds or removes 5 from the statefile every 1.2 seconds until 0 or 100 or when it gets terminated by the stop command.

statescount.sh:

state=$(cat /volume1/homeassistant/coverstate.state)
echo "Got state: $state"
if [ $state -lt "0" ] || [ $state -gt "100" ] ; then
	echo "State is Fuckedup! Resetting to 50"
	state=50
fi

if [ $1 = "U" ]; then
	echo "Selected Up"
	if [ $state = 100 ]; 
		then
			echo "Already Up dude!"
	else
		until [ $state -eq 100 ]; do
			echo "Going Up: $state"
			state=$((state+5))
        	echo $state > /volume1/homeassistant/coverstate.state
			sleep 1.3
     	done
    fi
fi

if [ $1 = "D" ]; then
	echo "Selected Down"
	if [ $state = 0 ]; 
		then 
			echo "Already Down dude!"
	else
		until [ $state -eq 0 ]; do
			echo "Going Down: $state"
			state=$((state-5))
        	echo $state > /volume1/homeassistant/coverstate.state
			sleep 1.3
     	done
    fi
fi

if [ $1 = "S" ]; then
	echo "Stop"
fi
exit 0

It’s not perfect but it works.

Hey devtone,
great solution and exactly what I need. I’ve got the command line cover running, except of the point in your script, where it calls the states.sh script. I’ve got hass.io running on a hyper-v. can you give me more details please, in which environment you’re running this?
I’m assuming, that hass.io can’t execute “screen” command.

thanks
Ralph

I had it bare metal at the time. Screen should work, you can install packages.