Renew bridge connection with rule after midnight

If you’re using Rules DSL, set up an API token and then use a rule like this to disable and re-enable the thing. I’ve shown the cron as 1:30am every day.

when
    Time cron "0 30 1 ? * * *"
then
    //Header for REST authentication
    //https://community.openhab.org/t/javascript-syntax-to-insert-api-token-into-sendhttpgetrequest/116798
    val headers = newHashMap("Authorization" -> "Bearer INSERT-API-TOKEN-HERE", "WWW-Authenticate"-> "Basic")

    //disable the thing
    sendHttpPutRequest("http://INSERT-IP-ADDRESS:8080/rest/things/INSERT-THING-ID/enable", "application/json", 'false', headers, 1000)

    //enable the thing
    sendHttpPutRequest("http://INSERT-IP-ADDRESS:8080/rest/things/INSERT-THING-ID/enable", "application/json", 'true', headers, 1000)
end

You might need to add a brief pause between the two commands.

If the Modbus thing shows up as offline and just doesn’t reconnect, you could instead trigger on its status.

UPDATE: This work up until OH 3.1, but in OH3.2 you need to change application/json to text/plain.

2 Likes