This is the code I’m attempting to use. I have a device that upon an http get, responds with json formatted data for temperature and humidity. Then it’ll turn around and publish it to Mosquito. I cannot get home assistant to accept my get_temperature.yaml file and it will not tell me the errors. Not even in logs. Anyone see any problems? (cut and paste may have messed up indention here, but it intellisense seems to pass it in studio code server.
- alias: "Get Temperature and Humidity"
trigger:
- platform: time_pattern
seconds: "/10" # Trigger every 10 seconds
action:
- service: http.get
# Replace with your device's IP address and endpoint
url: http://192.168.87.106
# Optionally, you can configure headers or authentication if needed
# Use data_template to extract data from JSON response
- service: mqtt.publish
data_template:
topic: "/homeassistant/home/workroom/"
payload: >
{% - set json_data = trigger.to_state.state_json -%}
{"temperature": {{ json_data.temperature }},
"humidity": {{ json_data.humidity }}}
# Add additional options like qos and retain if needed
qos: 0 # Quality of Service level
retain: false # Retain flag for MQTT message
You can then build an automation triggered from a change in those sensors to publish the data to MQTT if you need to, but get the first step working before trying to solve that one.
Totally agree. @jeffep — strongly advise not to use AI bots for HA, as they are terrible at it. If you must, please confess that you have done so in your post so we can disregard all of your code.
Thank you guys for your help. I did indeed use ChatGPT to help me create the code. I first started with Gemini which gave some help, then I used Copilot to get a different take. ChatGPT seemed to be the most complete.
You can bash them if you want. However, I find that the yaml configurations and automations in Home Assistant to be very cryptic. Documentation on API for this in Home Assistant should be front and center, and yet you must google and hack your way through. Also, as I stated, the ability to debug the yaml code within Home Assistant is very lacking. Without ‘Studio Code Server’ with intellisense, I wouldn’t even know about incorrect space alignment (which is another beef) as editing in ‘yaml mode’ from UI mode gives you almost no pointers on why Home Assistant doesn’t accept your code.
I appreciate your help with my current issue and will try this as you have stated and will let you know.
Whilst they hallucinate non-working code, I shall continue to bash them, Look what it’s given you: it’s just made a load of stuff up. It’s trained on old data, can’t distinguis one language from another, and can pull non-working code from forums like this to reinforce its “ideas”.
You do need to put some time in to learning them, agreed. It’s getting easier with more configuration going into the UI all the time.
It’s not the API, that’s something different. It’s general configuration that you want. I agree that it is hard to work out the best way to solve a problem, but once you have a route, the documentation is pretty good.
For example, here are the config docs for the rest sensor I gave you above:
Getting familiar with YAML syntax isn’t that hard: it’s very consistent and logical once you understand it. I do all of mine in vi with no debugging help.
However, you need less and less YAML as time goes on. Most automations and template sensors can now be fully set up in the UI — that sadly doesn’t yet include the RESTful sensor platform or integration.
You’re welcome, and feel free to ask any future questions on here. We’re a generally helpful bunch.
Another quick beef that I have while we’re on the topic. A long time ago when I was learning PHP, the documentation was excellent. Each function had it’s own page - like the RESTful page you gave me. However, at the bottom of each page, any programmer could add a little tip to the page which was great. For instance, when I get my device working (with your help) I could add a little tip to that page saying, “If you have a device … then this is the solution”. I mean look at that page - 1 example and then the config variables. It would be rare that someone needed that exact example. Most of us would have to spend an afternoon trying different settings to get it to work, only to find that HA won’t tell you why it’s not working.
Please don’t use it again. If you can’t recognise when it is just making things up that will never work it is wasting your time and ours when you come here asking why it does not work. Your time would be far better spent first asking here how to do things. We are happy to help and explain.
As for the documentation, it is quite logical once you understand how it is laid out. If you want more examples or feel an option needs further explanation there are links at the bottom of every page for suggestions, or to make edits yourself if you want to.
Ok. So instead of creating an automation to fire every 10 seconds, I added the rest: code provided by Troon, to my configuration.yaml file. I soft rebooted the server which didn’t work, so I hard rebooted. I know it’s working because after 3 gets, my device crashed and the HA System Log shows the failure.
So to see the good data that was produced, I’m looking for an integration? named rest? Or a sensor? device? named ‘Device temperature’? I go to Settings->Devices & Services, and I don’t find any listing for any of these in Integrations, Devices, Entities. Where is the data so that I may create a card for it for a dashboard?