Hello ,i need a rule so my google home mini announce the state o my Nest thermostat when it changes state (heating or off).I have the chromecast binding installed my google home mini working and voiceRSS right and tested.I just need the right rule syntax.
So you just want someone to write it for you?
Post your code… And we’ll help you make it work, or point you in the right direction.
Don’t expect people to write code for you.
Follow the tutorials for rules first:
https://www.openhab.org/docs/tutorial/rules.html
and
Have you read this page?
There are sample rules at the bottom.
sorry guys i was babysitting yesterday writing this post so i sounded like a jerk…i dont want someone to write the code for me ,i am an old dude here to learn.So here is my code that is working allright.
rule "say_thermostat"
when
Item HallwayThermostat_State changed
then
val Integer currentHour = now.getHourOfDay
if ((7..21).contains(currentHour)){
if (HallwayThermostat_State.state==('HEATING')) {
say("nest thermostat heating")
}
else {
say("nest thermostat off")
}
}
end
the only problem i have is with the volume.I use the
say("Hello world!", new PercentType(25))
and what i see is that my google home from volume 55 gets to 25 then back to 55 and then says “Hello world”.
What i want is to get from 55 to 25,say “Hello world” and then return to volume 55.
Try something like:
val Procedures$Procedure1<String> myCustomSayProcedure = [
myText |
val currentVolume = <google_home_volume_item>.state
if (currentVolume != 25) <google_home_volume_item>.sendCommand(25)
say(myText)
if (<google_home_volume_item>.state != currentVolume) <google_home_volume_item>.sendCommand(currentVolume)
]
rule "say_thermostat"
when
Item HallwayThermostat_State changed
then
val Integer currentHour = now.getHourOfDay
if ((7..21).contains(currentHour)){
if (HallwayThermostat_State.state==('HEATING')) {
myCustomSayProcedure("nest thermostat heating")
} else {
myCustomSayProcedure("nest thermostat off")
}
}
end
First, if you are here to learn, good, but stay out of Function and Procedures lambas. They are complicated.
Although it’s a good example and the code is sound it won’t work.
The reason is that the say
command take a few milliseconds in openHAB and then the volume will be reversed. You need to know how long “nest thermostat heating” takes to say. Including the time for the google home to take the command etc…
You will need the google volume item:
Number GoogleVolume { channel="xxxxx" }
Then use a timer:
Replace the 10
with the time is takes for your speaker to say the sentence
var volume = null
rule "say_thermostat"
when
Item HallwayThermostat_State changed
then
val Integer currentHour = now.getHourOfDay
if ((7..21).contains(currentHour)) {
volume = storeStates(GoogleVolume)
if (HallwayThermostat_State.state==('HEATING')) {
say("nest thermostat heating")
createTimer(now.plusSeconds(10), [ |
restoreStates(volume)
])
} else {
say("nest thermostat off")
createTimer(now.plusSeconds(10), [ |
restoreStates(volume)
])
}
}
end