Integrate Silverbullet with Home Assistant (and more)

I love the idea of connecting Home Assistant to Silverbullet.

But instead of using a shell script I would recommend directly http.request’ing using the built in http.request function. which for HomeAssistant would look something like this to get the temperature from HomeAssistant weather forecast entity:

function getWeatherHASS()
       local HA_URL = "https://your.hass.url/api/states/"
       local ENTITY = "weather.forecast..."
       local HA_TOKEN = "YOUR_API_KEY"
    
       local url = HA_URL .. ENTITY
       local headers = {
            ["Authorization"] = "Bearer " .. HA_TOKEN,
            ["Content-Type"] = "application/json" 
           }
       local response = http.request(url,{method = "GET", headers = headers})
       local result = response.body.attributes.temperature
   return result .. "°C"
end  

of course this is just a proof of concept only.

and instead of storing the temperature in a page, why not use the datastore API and store the temperature in the clients storage and refresh only if it’s older than 60 min. this way you don’t need to run the request every time you need the temperature, you just fetch it from datastore, and if timestamp is older than 1h then and only then make a request to home assistant.

Here is an example of how to store weather information using the datastore:

if you need help with it just shout.

2 Likes