Shelly 1 - Set temperature via http

Hi,

I successfully set up a floor heating automation with openHAB based on several Shelly 1. I read the actual temperature and control the relay via MQTT. That works like a charm. However, I currently decide against performing the temperature automation fully in openHAB since Shelly allows setting a minimum temperature and a maximum temperature where the relais automatically switches on or off.
In the worst case, if openHAB is down, the Shellys can work independently and switch on/off the relay.

That means in the rules I just calculate the upper and lower temperatures based on the user input on a dashboard and send it to the Shelly:

// WC: Neue Werte an Shelly via HTTP schicken
rule "WC_Thermostat_SetShelly"
when
    Item vIt_HZ_EinschaltNacht changed or
	Item v_Heizung_Einschalt_WC changed or
	Item vIt_HZ_Tag changed
then	
	var Double Abschaltwert 
	var Double Einschaltwert	
	if(vIt_HZ_Tag.state==ON){		
		Abschaltwert = ( v_Heizung_Abschalt_WC.state as Number ).doubleValue()
		Einschaltwert = ( v_Heizung_Einschalt_WC.state as Number ).doubleValue()
	} else {		
		Abschaltwert = ( vIt_HZ_AbschaltNacht.state as Number ).doubleValue()
		Einschaltwert = ( vIt_HZ_EinschaltNacht.state as Number ).doubleValue()
	}
	// http Befehl an Shelly senden
	var String httpString = ""
	
	httpString = "http://192.168.188.70/settings/ext_temperature/0?overtemp_threshold_tC=" + String::format("%.2f",Abschaltwert)
	sendHttpGetRequest(httpString)
	logInfo("WC_Thermostat_SetShelly", "Rule WC_Thermostat_SetShelly: " + httpString)
	
	httpString = "http://192.168.188.70/settings/ext_temperature/0?undertemp_threshold_tC=" + String::format("%.2f",Einschaltwert)
	sendHttpGetRequest(httpString)
    logInfo("WC_Thermostat_SetShelly", "Rule WC_Thermostat_SetShelly: " + httpString)
end

Inspired by: kriwanek.de

I would like to refactor my code. You can imagine that this approach creates lots of redundant code. My current approach would be grouping the items so that one rule can handle all Shellys (which is very well explained here in this forum in the DP section). What is missing for me: How do I store the IP of the Shelly? Currently it is hard coded in the rule which is why there is one rule for each Shelly. If I would program it in Java I would just add another attribute to the MQTT item containing the static IP. In the rule I would fetch the IP from this attribute to build up the necessary http-call. How is the concept in openHAB? Where would I store such meta information? In a sitemap? With a virtual item per IP?

Looking forward :slight_smile:

See Design Pattern: Encoding and Accessing Values in Rules. Since you are using Rules DSL some of the options like Item Metadata won’t be an option, but several of the techniques discussed there will work.

Brilliant! Thanks a lot! I think I will go with the approach where one populates a HashMap at system start containing the IP addresses.

Is it beautiful? Meh… not really. A pitty that Shelly does not support setting temperatures via MQTT. But if it works, it works I guess. :slight_smile: