Good afternoon.
Fairly new to Home Asisstant not a programmer but loving it already.
With the help of this community and HA documentationI have build a small setup on Rasberry PI 3b with Hass.io. Tried for a few days to automate a light based on a sensor value but cant seem to achieve it the way I want it.
In binary_sensors.yaml I have setup a Wemos D1 mini module flashed with Tasmota fw.
It works as expected with a reed switch and a magnet attached to a garage door.
- platform: mqtt
name: "Wemos1"
state_topic: "stat/Wemos1/POWER"
payload_open: "ON"
payload_close: "OFF"
device_class: garage_door
retain: true
In switches.yaml there is a switch for the garage door light.
The actual switch is a simple 433Mhz module that I send the commands via Sonoff RF Bridge flashed with Tasmota fw. Switch works as expected.
- platform: command_line
name: "Door Light"
switches:
door_light:
command_on: "/usr/bin/curl -X POST local.ip/cm?cmnd=RFKey6"
command_off: "/usr/bin/curl -X POST local.ip/cm?cmnd=RFKey7"
assumed_state: false
retain: false
In automation.yaml I have this code right now but not working:
- alias: 'Auto Door Light'
initial_state: 'on'
hide_entity: False
trigger:
platform: state
entity_id: binary_sensor.wemos1
action:
service: switch.turn_on
data_template:
entity_id: switch.door_light
value: >-
{% if is_state('binary_sensor.wemos1', 'on') %}
command_on: "/usr/bin/curl -X POST local.ip/cm?cmnd=RFKey6"
{% else %}
command_off: "/usr/bin/curl -X POST local.ip/cm?cmnd=RFKey7"
{% endif %}
Tried for a couple days with different ways to automate the light based on the sensor value but with no success.
In the front end I have this:
Door Status is the sensor
Door Light is the switch
Auto Door Light is the automation I am trying to build.
What I would like to happen is when the garage door opens the door light turns on,
when the garage door closes the light turns off.
The automation would be best to be a single switch, like it appears now in the front end
so it can be enabled/disabled at will.
Second, ideally I would like to have a sensor and/or switch availability indication.
i.e. If a sensor loses power, gets unplugged from mains, or power is cut I would like to have an indication
of that in the topic. i.e. Where Door Status says open/closed if the sensor looses power it should say unavailable/offline for example. Tried a couple of settings for that, didn’t work out.
I find the availability to be of crusial importance in terms of security especially if someone plans to build an alarm based on Home Assistant.
Any advice welcome.
Thank you