Automatic Shading with Astro, OpenWeather and MqTT (for Shelly 2.5)

So how can i try to set values without x.5?

Ruben Fuser

Try it.
Please check also if your weather binding send the values with out .X
Do you use “VS-Code” for editing your files ?
With VsCode you can also see how the actual values are set.

No i use only nano editor…

Ruben Fuser

Therefore i recommend to use Vs code

But why all other people don’t have this problem with decimals for azimuth/elevation?

Ruben Fuser

Thinking about it…no the problem cannot be that because you should have the same problem and everyone else…

I don’t if this your problem.
It’s only an idea.

How about the Cloudiness State ?
Take a look on to the “UoM” Units of Measurement
Does the percentage from your Weatherbinding come with lets say 20% in the system ?
The Rule wont accept the % (UoM) with this Value.
The Rule only accept Numbervalues with out UoM
image
You see here my “Current Cloudiness” shows only “40”
I use this in the rule.
Originally the Cloudiness comes from the Weatherbinding with % like the Forecast: 45%
Probably this is why the Rule wont trigger

BR Peter

Hi Peter,

Thank you for your tutorial. Can you tell me which weather provider you are using with your weather binding? How accurate is the information about the cloudiness?

Best regards

Johannes

Hi,
I use the OpenWeatherMap binding.
The accuracy is for my setting ok.
The value for the cloudiness goes from 0% to 20%
and 40% and 60%.
It’s ok here

Br

in events.log i have these values:

2019-09-02 09:06:41.805 [vent.ItemStateChangedEvent] - LocalWeatherAndForecast_Current_Cloudiness changed from UNDEF to 75.00
2019-09-02 09:06:41.808 [vent.ItemStateChangedEvent] - AussenTemp changed from UNDEF to 19.08 °C
2019-09-02 09:04:38.003 [vent.ItemStateChangedEvent] - Azimuth changed from 102.8020143705597 ° to 102.80202080446743 °
2019-09-02 09:04:38.027 [vent.ItemStateChangedEvent] - Elevation changed from 23.32893376890503 ° to 23.328939359793026 °

any clue?

hi ruben,

all your items a showing a °C or °
The Rule need the for example the “AussenTemp” Outside Temperature like this: 19.08 WITHOUT “°C”
Also the angle of AZ and ELE no ° behind the number…
Otherwise the Rule wont work.

BR Peter

how can i translate this in English?

Rolloautomatik_oeffnen

thanks

real word for word translation:

blindsautomatic_open

With this you can enable the automatic, to open the blinds when the configured things are true.

perfect! thanks a lot! i’m editing and translating in english the rule/item/sitemap.
i’ll post the complete version soon so everyone can enjoy this :slight_smile:

here you are all englished files. hope the translation is approx ok :wink:
this should be okay, i’ve formatted datetime and corrected some lines around here and there.

shading.items

Group		gRolloautomatik				"Gruppo Tapparelle Ovest"

Switch		Rolloautomatik																					//"Automatic blinds closing"
Switch		Rolloautomatik_Open																				//"Inverts blinds Closing with opening"

Number		Rolloautomatik_Closure																			//"Blinds closed at"
Number		Rolloautomatik_Temperature																		//"Temperature higher than: [%1$.0f]"
Number		Rolloautomatik_Cloudiness																		//"Cloudiness higher than: [%d]"
Number		Rolloautomatik_Azimuth																			//"Sun Azimuth higher or equal to: [%d]"
Number		Rolloautomatik_Elevation																		//"Sun Elevation higher or equal to: [%d]"

DateTime	Rolloautomatik_Last_Start																		//"Last run (Close) [%1$tH:%1$tM %1$td/%1$tm/%1$tY]"
DateTime	Rolloautomatik_Last_End																			//"Last run (Open) [%1$tH:%1$tM %1$td/%1$tm/%1$tY]"

Number		External_Temperature		{weather="locationId=home, type=temperature, property=current"}		//"Temperature [%.0f]"
Number		Local_Cloudiness			{weather="locationId=home, type=clouds, property=percent"}			//"Clouds [%.0f]"
Number		Azimuth						{channel="astro:sun:home:position#azimuth"}							//"Azimuth [%.0f]"
Number		Elevation					{channel="astro:sun:home:position#elevation"}						//"Elevation [%.0f]"

shading.rules

var boolean log = true
rule "Blinds closure"
when Item Azimuth changed
then
    val String logPrefix = 'Autoblinds (Blinds closure) - '
    if (log) logInfo('rules', logPrefix + 'Rule loaded!')
    
    var String timeLast = 'xxxx-xx-xx'
    if (Rolloautomatik_Last_Start.state == NULL) 
		{
			if (log) logInfo('rules', logPrefix + 'First execution on this system.')
		} 
	else 
		{
			timeLast = Rolloautomatik_Last_Start.state.toString().substring(0,10)
		}

var String timeNow = now.toString().substring(0,10)

    if (Rolloautomatik.state == ON) 
		{
			if (timeNow != timeLast) 
				{
					if (Azimuth.state > Integer::parseInt(Rolloautomatik_Azimuth.state.toString())) 
						{
							if (External_Temperature.state > Integer::parseInt(Rolloautomatik_Temperature.state.toString())) 
								{
									if (Local_Cloudiness.state  >= Integer::parseInt(Rolloautomatik_Cloudiness.state.toString())) 
										{
											if (Elevation.state > Integer::parseInt(Rolloautomatik_Elevation.state.toString())) 
												{
													if (log) logInfo('rules', logPrefix + 'Blinds have been closed.') gRolloautomatik.members.forEach
													[i| if (i.state <= Integer::parseInt(Rolloautomatik_Closure.state.toString())) {if (log) logInfo('rules', logPrefix + 'Blind set to ' + Rolloautomatik_Closure.state.toString() + '%: ' + i.name) i.sendCommand(Integer::parseInt(Rolloautomatik_Closure.state.toString()))} else {if (log) logInfo('rules', logPrefix + 'Blind already closed (' + i.state.toString() + '%) so rule will be skipped')}]
													sendBroadcastNotification("Auto closure enabled!")
													Rolloautomatik_Last_Start.postUpdate(now.toString())
												}
											else 
												{
													if (log) logInfo('rules', logPrefix + 'Sun elevation (' + Elevation.state.toString() + ') has not reached the value set (' + Rolloautomatik_Elevation.state.toString() + ')')
												}
										}
									else
										{
											if (log) logInfo('rules', logPrefix + 'Cloudiness (' + Local_Cloudiness.state.toString() + ') has not reached the value set (' + Rolloautomatik_Cloudiness.state.toString() + ')')
										}
								}
							else
								{
									if (log) logInfo('rules', logPrefix + 'Temperature (' + External_Temperature.state.toString() + ') has not reached the value set (' + Rolloautomatik_Temperature.state.toString() + ')')
								}
						}
					else
						{
							if (log) logInfo('rules', logPrefix + 'Azimuth (' + Azimuth.state.toString() + ') has not reached the value set (' + Rolloautomatik_Azimuth.state.toString() + ')')
						}
				}
			else
				{
					if (log) logInfo('rules', logPrefix + 'Task finished. The rule will not be executes again today.')
				}
		}
	else 
		{
			if (log) logInfo('rules', logPrefix + 'Finished, automation disabled.')
		}
end

//-----------------------------------------------//

rule "Blinds opening"
when Item Elevation changed
then
    val String logPrefix = 'Autoblinds (Blinds opening) - '
    if (log) logInfo('rules', logPrefix + 'Rule loaded!')

    var String timeLastEnde = 'xxxx-xx-xx'
    if (Rolloautomatik_Last_End.state == NULL) 
		{
			if (log) logInfo('rules', logPrefix + 'First execution on this system.')
		} 
	else 
		{
			timeLastEnde = Rolloautomatik_Last_End.state.toString().substring(0,10)
		}

    var String timeLastStart = 'yyyy-yy-yy'
    if (Rolloautomatik_Last_Start.state == NULL) 
		{
			if (log) logInfo('rules', logPrefix + 'First execution on this system.')
		} 
	else 
		{
			timeLastStart = Rolloautomatik_Last_Start.state.toString().substring(0,10)
		}

	var String timeNow = now.toString().substring(0,10)

    if (Rolloautomatik_Open.state == ON) 
		{
			if (Elevation.state <= Integer::parseInt(Rolloautomatik_Elevation.state.toString())) 
				{
					if (timeLastStart == timeNow) 
						{
							if (timeLastEnde != timeNow) 
								{
									if (log) logInfo('rules', logPrefix + 'Blinds opened') gRolloautomatik.members.forEach
									[i| if((Rolloautomatik_Closure.state as Number).intValue <= (i.state as Number).intValue +5 && (Rolloautomatik_Closure.state as Number).intValue >= (i.state as Number).intValue- 5) {if (log) logInfo('rules', logPrefix + 'Blind set to 0%: ' + i.name) i.sendCommand(0)} else {if (log) logInfo('rules', logPrefix + 'Blind not completely opened by script to 0%, because manually managed: ' + i.name)}]
									sendBroadcastNotification("Auto open finished")
									Rolloautomatik_Last_End.postUpdate(now.toString())
								} 
							else 
								{
									if (log) logInfo('rules', logPrefix + 'Task finished. The rule will not be executes again today.')
								}
						} 
					else 
						{
							if (log) logInfo('rules', logPrefix + 'Finished. No task has been executed today. No auto opening can be executed.')
						}
				} 
			else 
				{
					if (log) logInfo('rules', logPrefix + 'Elevation (' + Elevation.state.toString() + ') has not reached the value set (' + Rolloautomatik_Elevation.state.toString()+ ')')
				}
		} 
	else 
		{
			if (log) logInfo('rules', logPrefix + 'Finished, automation disabled.')
		}
end

shading.sitemap

sitemap shading label="Blinds Auto close"

{
	Frame label="Enable automation" 
		{
			Switch item=Rolloautomatik label="Blinds Auto closure"
			Setpoint item=Rolloautomatik_Closure minValue=0 maxValue=100 step=1 label="Blinds closed at: [%s %%]"
        }

	Frame label="Close if..." 
		{
			Setpoint item=Rolloautomatik_Temperature minValue=0 maxValue=35 step=1 icon="temperature" label="Temperature higher than: [%s °C]"
			Text item=External_Temperature icon="temperature" valuecolor=[>27="red",>20="orange",>10="purple",>5="green",<=5="blue"] label="External temperature: [%.0f °C]"
			Setpoint item=Rolloautomatik_Cloudiness minValue=0 maxValue=100 step=20 icon="sun_clouds" label="Cloudiness higher or equal than to: [%.0f %%]"
			Text item=Local_Cloudiness icon="sun_clouds" label="Cloudiness: [%.0f %%]"
			Setpoint item=Rolloautomatik_Azimuth minValue=0 maxValue=360 step=50 icon="niveau" label="Azimuth higher than: [%d °]"
			Text item=Azimuth icon="niveau" label="Azimuth: [%d °]"
		}

	Frame label="Open if..." 
		{
			Switch item=Rolloautomatik_Open label="Enable auto opening"
			Setpoint item=Rolloautomatik_Elevation minValue=-20 maxValue=60 step=1 icon="sun" label="Elevation less than: [%d °]"
			Text item=Elevation icon="sun" label="Elevation: [%d °]"
		}

	Frame label="Info"
		{
			Text item=Rolloautomatik_Last_Start label="Last run (Close) [%1$tH:%1$tM - %1$td/%1$tm/%1$tY]"
			Text item=Rolloautomatik_Last_End label="Last run (Open) [%1$tH:%1$tM - %1$td/%1$tm/%1$tY]"
		}
}

1 Like

:+1:

Hi Peter,

sorry one more question: Why are you using the elevation to open the rollershutters? I have rollershutter on the east and on the west side (a lot inside the roof) and think about it to use the azimuth to find the right position for open the shutters. The max elevation change during the year and I want to switch the closed (and opposite the opened) side nearly at lunch time.
Can you explain me your solution? Is it possible to archive it?

Best regards and Thank you

Johannes

Hi Johannes,

i use the elevation to open the rollershutters because of our houses in the neighborhood.
At the certain point of elevation (around 12°) the sun disappears behind the neighborhood houses.
But i real live we dont use the automatic open :slight_smile: Because when the sun is gone, it´s also time to put the kids in to bed. So we dont need to open the shutters :slight_smile:
This summer we only use the automatic closing.

Br Peter

Hello Peter,
Me again:-), can you please explain me the substring(0,10) expression, what does it makes with the timestamp?

Thank you!