I’ve reached the limit of my knowledge on this one and can’t seem to find the right google phrase to help me through.
I am trying to have an ESP check a url based on an RFID ID and the MAC Address.
If it gets a response, it turns on a relay. Otherwise nothing.
#Setup RFID Reader, tag read acknowledgement, HTTP Auth Request
pn532_i2c:
update_interval: 1s
on_tag:
then:
- light.turn_on:
id: swled
flash_length: 0.5s
- http_request.get:
url: !lambda |-
"http://192.168.0.5/" 'return {WiFi.macAddress().c_str()};' "/" 'return x;' "/"
headers:
Content-Type: application/json
verify_ssl: false
on_response:
then:
- switch.turn_on: relay_1
#!lambda 'return {WiFi.macAddress().c_str()};' #Send MAC address for machine ID
#!lambda 'return x;' #This is the RFID UID
Ideally, I would like to flash the light if I got anything other than a 200 response but beyond me at the moment. Any help from the more software minded folk much appreciated.
For starters, note that a lambda is supposed to be actual C++ code. So the line that begins with a quoted string (the URL) is not valid C++ code.
You can provide the URL as a normal YAML element if it is a static string, or use a lambda and C[++] code to compose the URL string before returning it.
So, for example, I use HTTP from the ESPHome device to control another device.
It enslaves a second dimmer to the one running this code. It looks up the current brightness, and reads a global variable containing the target hostname (there are more than one) then composes the URL that will command them.
Your url: lambda should return only the URL string - it does not do processing of the returned value under the url: tag.
Here, I compose the URL string using some C string operation calls: