I am new to HA and migrating my stuff from openhab to HA.
The RESTful binary_sensor help on this forum is unfortunately above my head.
So I could need some help on this pretty simple example (I suppose).
I would like to create a RESTful binary sensor and would like to trigger this from my alarmsystem (Lupus XT1).
More precisely I would like to set the binary_sensor to ON from the Alarmsystem (Motion sensor) and use this in HA.
I have created the stuff in configuration.yaml
# RESTful binary sensor for input by Lupus (Motion detector)
binary_sensor:
- platform: rest
name: binary_sensor.bewegung_wozi
device_class: motion
resource: http://192.168.68.70/bewegung_wohnzimmer
method: POST
I am unclear about what to do next.
Do I need to create the sensor itself in the “Helpers” area?
If so, how to hook it up to the RESTful binary_sensor?
How to adress / set the binary_sensor to ON?
From my Alarmsystem I can trigger something like (from my memory on openhab):
It’s going to depend a great deal on the Lupus XT1. First, why are you doing POST method if you aren’t posting something? Second, you have to do something with the returned information and use it to create the value for the sensor. If it’s a JSON, you can add stuff from the response to the sensor attributes which you can use in the value template to get the right sensor status.
This is for a regular sensor of mine, not a binary one, but the principle should be the same:
- platform: rest
resource: http://172.16.1.2/discover.json
name: HDHomerun 2 Info
json_attributes:
- FriendlyName
- ModelNumber
- FirmwareName
- FirmwareVersion
- DeviceID
- DeviceAuth
- UpgradeAvailable
- BaseURL
- LineupURL
- TunerCount
- ConditionalAccess
value_template: >-
{% if value_json.UpgradeAvailable is defined %}
Upgrade Available
{% else %}
OK
{% endif %}
You’ll have to figure out the value template so that it always gives back on or off.
Follow up note. The restful binary sensor can’t have a json_attribute entry, so this example is of limited value in this thread. I’m leaving it just for context.
No, you have created the sensor in YAML. You only need to do a configuration check (Developer Tools → YAML) and restart Home Assistant if the check passes. However…
It is a sensor. You do not change the state of sensors. Sensors are inputs to Home Assistant that change state outside Home Assistant. Home Assistant just monitors this state with the sensor. There is no control of sensors.
Perhaps you wanted the restful switch instead?
A switch is an output you can use to control things. It has the ability to monitor the current state of the external switch with a template if something outside Home Assistant changes the switch state.
Unfortunately I don’t see the sensor in the entities section of the UI.
Yes, that’s my idea behind it:
I expose a sensor from HA to the outer world which is monitored by HA.
The Alarmsystem changes the state of the sensor with a http command and HA recognizes the change (motion detected).
Thank you, Glenn.
Will do and try my best
I just used what worked for me in the past from openhab.
I actually don’t care, but just want to get the “ON” signal to HA.
So how does the http call look like if I want to change the exposed binary_sensor to ON?
I googled “Home Assistant Lupus XT1” and this popped up:
I assume you tried this already? If not consider trying this first. If so and it didn’t work for you then consider making a #feature-requests for what you found it is lacking.
Assuming you did try it and found it lacking and need to go a more custom route, from what you’re saying I don’t think you want a REST integration at all. RESTful sensors and switches use a polling model. They periodically call a URL to ask some device/service what state it’s in and (if its a switch) call another URL to turn it on or off.
You’re describing a push model. Your alarm system is able to send a command when it updates with that state. In that case you want a webhook. Using a webhook trigger anywhere in HA makes an endpoint your alarm system can post its state to.
You can use this type of trigger in an automation. Or if you want to make a sensor out of it, you can use a trigger-based template sensor. Your use case is basically identical to the linked example.