Announce the time and weather via tts

Looking to announce the time and weather every hour. I’d also like to have these announcements shut off between say 10PM and 7AM. I am stumped as to how to do it.

See Design Pattern: Time Of Day for a good way to track the time of day.

At a high level, you need to

  • configure Voice so the say action will work
  • write a Rule that triggers every hour using a cron trigger
  • in that rule use the say action to say the time and weather based on the States of Weather Items

In addition to the hints from @rlkoshak you’ll need to have a configured Audio Sink (in order to give OH directions where to play the text).
See this recent discussion VoiceRSS Customizing

1 Like

How do i get the states of items into the say action?

Please read the beginners tutorial and rules Schaller of the user’s guide.

The documentation does not give any guidance on returning the state of an item as part of the say command.

It does, all over the place. There are examples left and right.

This section of the Rules docs probably provides the most in-depth discussion of how to access and manipulate an Item’s state.

1 Like

@rlkoshak
I think links aren’t taken as a valid answer by him. We should better write the complete code for him.
However, I won’t.

Been there, done that. I rarely will anymore.

And this one is so easy. One could almost just.state it.

It has nothing to do with links aren’t a valid answer for me, but more that
a little more than an RTFM would be nice from the community.

Well , honestly, the question you are asking is SO basic to how OH works it comes across as if you are not reading the docs at all. We are not terribly willing to spend time helping those who are not willing to read the docs we also spent a lot of time writing.

As I hinted above, you reference the state of an item using .state.

say(MyItem.state)

I appreciate the candor. I’ll give that a shot, I recall trying it and it puking on it. Thank you. I’ll make sure to dig deeper into the documentation.

Now that is the sort of question we welcome and jump to help with. You gave it a shot and it didn’t work. That shows you are trying and at least made some effort to read up how to do it.

What specifically didn’t work? What sort of errors did you see in the logs or Designer?

Try

say(MyItem.state.toString)

When dropping to Karaf console, and issuing the smarthome:voice say command, which is working with something simple like say hello, i get the following:

openhab> smarthome:voice say the current temperature is (CurrentTemperature.state.toString)
Command not found: CurrentTemperature.state.toString

I’m not sure how to do that from the karaf console. I don’t think it is intended to be used that way there. Typically one would use a Rule and issue the say command as I placed it above in the Rule. I think the konsol say command is primarily there to test that it works.

I’ll second that statement. Using the console you can’t access the item states.
Have a look onto an old post of my “say” rule using Sonos boxes.Old Post
The first string in the say command is the text which is sent to the TTS service. It could as well be composed of several parts like:

  say("Die aktuelle Temperatur ist "& Temperature.state.toString, & "Grad.""voicerss:deDE",AudioSink)

Here’s the error message I am receiving. I trigger this rule off of the state of a switch called timeandtemp

Code:
rule "Time and Temp"
when
Item timeandtemp changed
then

if ((timeandtemp.state == ON)) {
sendCommand(say, “The current time is”)

sendCommand(say, currenttime.historicState(now.minusSeconds(0)).state)

sendCommand(say, "and the current temperature is")

sendCommand(say, CurrentTemperature.historicState(now.minusSeconds(0)).state)

sendCommand(say, "Degrees Farenheit.")

}
end

say isn’t an Item. You can’t sendCommand and postUpdate to it. That is only for commanding or changing the states of Items.

say is an Action. You just call it.

say("The current time is ")

Why are you getting historicState from a second ago? Is there a reason why you don’t just use its current state?

say(currenttime.state.toString)

And as I did above, you might need to call toString on the state in some circumstances.

You never actually posted the error you are receiving, just the code.

Finally, it is easier for us to read code if you use code fences. Press the button with </> or

```
code goes here
```

Ok, having progress. I can make it either say “the time is” or speak the time. Using the example provided by Jurgen above, i get the following error in designer:

Multiple markers at this line

  • extraneous input ‘)’ expecting ‘}’
  • The method or field currenttime is undefined
  • no viable alternative at input ‘&’
  • missing ‘)’ at ‘currenttime’
  • The method say(String) is undefined

Here’s the code:

rule "Time and Temp"
when
    Item timeandtemp changed
then


  if ((timeandtemp.state == ON)) {
    
	say ("The Time is "& currenttime.state.toString)
	
  }
end

try so, I did not check

if (timeandtemp.state == ON) {
	say ("The Time is "& currenttime.state.toString)
  }