This is exactly what I had to do for my GogoGate2 garage opener I have which isn’t a component in HA.
I wish there was an easier way but I seem to get it to work.
So I create a command line “cover” to control the garage opener.
cover:
platform: command_line
covers:
garage_door:
command_open: curl --silent -X GET https://maker.ifttt.com/trigger/OpenMyGarage/with/key/KEY?value1=Opened
command_close: curl --silent -X GET https://maker.ifttt.com/trigger/CloseMyGarage/with/key/KEY?value1=Opened
command_state: /home/pi/hass.shell.commands/garage/checkG2Sensor.sh
Open and Close command is straightforward, it calls IFTTT maker to call GogoGate2 IFTTT functions to open and close.
The tricky part is the command to set the state for this “cover” component.
First, I created a template sensor to keep track of the garage opener state. This sensor is also used on my Dashboard.
- platform: template
sensors:
gogogate4dash:
value_template: >-
{%- if is_state('sensor.gogogate2', '0') -%}
CLOSED
{%- elif is_state('sensor.gogogate2', '100') -%}
OPEN
{%- else -%}
CLOSED
{%- endif -%}
As you can see,it checks the state of an HTTP sensor (sensor.gogogate2) which isn’t existed when HA starts; but that’s ok… as I treat it initially as “CLOSED” (in the last ‘else’ block), then on the first motion, it’d be updated accordingly.
Here is how it all works together:
When my garage close or open, Gogogate2 sends me a notification on the phone, I setup Tasker to detect that and call HA to update the HTTP sensor; with ‘{“state”: “0”}’ for closing and ‘{“state”:“100”}’ for opening. That would update the template sensor with proper status (CLOSED or OPEN)
Then in the command line script (that updates the cover component status listed above) will keep checking this template sensor.
#!/bin/bash
U="https://nguyenha.duckdns.org/api/states/sensor.gogogate4dash?api_password=HA_PASS"
R=`curl --silent -X GET $U | jq -r '.state'`
if [[ $R == "CLOSED" ]] ; then
echo "0"
else
echo "100"
fi
And voila, as HA starts, my Cover component is working with proper state (assuming the garage is actually closed, hahaha)
It looks like a complicated process but it has to be this way