How do i run rule on page load?

Using openhab 3 running on debian 10.

I have a device (an inverter) that logs data via mppt, I can read and load said data in openhab fine.

The mppt publishing of data times out every 60 seconds and will restart sending data if I publish a message on the mppt topic like a keep alive message.

I can write a rule for that however I’d quite like to only send that “keep awake” message when someone is using openhab rather than constantly have mppt data being sent. Is there a way to write a rule to run the keep awake message when page is loaded. ie someone is using openhab.

I did think maybe adding something into web files like the actual index.html files in openhab but I imagine there’s a cleaner/inbuilt solution for this?

Thanks,
Matt.

No, there is no way I can think of.

You could trigger a rule from a widget that a user interacts with (e.g. a button) or somehow otherwise update or command an Item, but there is no event on the load of a page.

The cleaner solution is to just keep the sensor reporting to the MQTT(?) without timing out. The fact that it times out is kind of an anti-pattern for MQTT. The publisher should publish when ever it has something worth publishing. It shouldn’t fall asleep and require prodding to do its job.

Thanks @rlkoshak,

*sorry MQTT got solar on the brain with MPPT.

I guessed that would be the recommended answer. The MQTT sleeps I think to prevent overloading the solar providers cloud which already reads the data (not directly from MQTT but that is the source), I’m then piggy backing on those data sends.
Seeing as i only need the data to update when someones looking at openhab i thought there might be a way to only keep awake when I’m looking rather than all the time as a some what middle ground, ie not constantly sending data but also not never sending data. Given OH doesnt have a solution looks like i’ll do as suggested and edit the publishes to be constant and not timeout.

Thanks for the help.

The middle ground would be to make an item that you have to turn ON when you want to update the data. That would trigger a rule that refreshes the data, and reset the item to OFF.

Hey russ I tried your idea

I can see in mosquitto Linux client that the keepalive sketch item is working and data is being spammed into topics but the items that store the information don’t update.

They only update if I go into the mqtt bridge thing or channel thing and just press save
Almost like the connection has timed out when no data has been seen in topics. If I don’t let the mqtt server to stop sending data there’s no issues.

The server doesn’t shutdown as I can still access it. Using mosquitto in Linux. Is there a sleep setting in openhab mqtt addon I can disable?

I’m confused by what you’re describing. As far as I’m ware, openHAB shouldn’t be timing out at all, but it will stop updating if it loses the connection to the MQTT broker. However, “loses the connection” is not the same as “there’s no MQTT traffic right now”. If there’s no traffic, openHAB will just update things with the existing values (even though they haven’t changed). And from what you’ve said, the broker is actively receiving constant traffic from the inverter (as should be the case). If that’s really the case, openHAB should be constantly updating.

You can try playing with the Reconnect Time and Heartbeat parameters in the MQTT bridge thing, but I’ve never needed to do that so I can’t tell you what would be better than the 60-second defaults.

Maybe the real question here is: why does your MQTT broker close its connection to openHAB? I don’t know how you’ve set yours up, but there are some configuration settings you might want to check.

You could also try experimenting with a different broker to see if the behaviour is different. Perhaps set up a free beebotte account for testing purposes.