Tag: curl

Using the REST api to read sensors on Home assistant

During one of my little project of making timelapses videos with some IP cameras, I had the following problem : How do you stop capturing new images at night when the camera see nothing,
After all , the sun rise and sun set time are changing everyday ! and i didn’t see a simple way to calculate this.
then i remembered the sun.sun integration in Home assistant.

If i had a simple way to query this integration in my script , i could very simply stop my script when the sun was no longer present in the sky !

The Home assistant REST API

In any home assistant installation there is access to a REST API that lets you do a lot a things , but in my case, I don’t want much , I just want to know if the sun is above or below the horizon.

  1. Get a Authorization: Bearer token
    you first have to generate a token to authenticate your request . You have to go to your user section , this is the circle a the bottom of the toolbar, then at the bottom of the page , you can create a long term token ,
    Please take note of this token because Home assitant can only display it one time , if you loose it , you must recreate an other one.
  2. Then in my script i can use this
  3. it will return either above_horizon or below_horizon, I can then use this in my script to stop the capture when it’s below_horizon

I used jq filter the json result , but , if you can’t or don’t want to install it , you can replace it with this simple awk

InfluxDB insert multiples values at once using curl

If you have to insert multiples values in an influxdb database. You can use curl and insert the values one at the time.

But there is a better way like in this example

Let’s say you want to insert your tree loadaverage values in you influxdb database.

First put them into variables using these 3 lines.

Then using this curl line, insert them all at once in your influxdb database