# Announce the time and weather via tts

**URL:** <https://community.openhab.org/t/announce-the-time-and-weather-via-tts/34813>\
**Category:** Text-to-Speech\
**Created:** [October 4, 2017, 9:01pm UTC](https://community.openhab.org/t/announce-the-time-and-weather-via-tts/34813 "2017-10-04T21:01:18Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steven\_Ferguson](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/65b543/32.png) [@Steven\_Ferguson](https://community.openhab.org/u/Steven_Ferguson)\
**Post date:** [October 4, 2017, 9:01pm UTC](https://community.openhab.org/t/announce-the-time-and-weather-via-tts/34813/1 "2017-10-04T21:01:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [October 4, 2017, 9:48pm UTC](https://community.openhab.org/t/announce-the-time-and-weather-via-tts/34813/2 "2017-10-04T21:48:34Z")

</div>

See [Design Pattern: Simple State Machine (e.g. Time Of Day)](https://community.openhab.org/t/design-pattern-time-of-day/15407) for a good way to track the time of day.

At a high level, you need to

- [configure Voice](http://docs.openhab.org/addons/voices.html) so the say action will work
- write a [Rule](http://docs.openhab.org/configuration/rules-dsl.html) that triggers every hour using a [cron trigger](http://docs.openhab.org/configuration/rules-dsl.html#time-based-triggers)
- in that rule use the [`say`](http://docs.openhab.org/configuration/multimedia.html#text-to-speech) action to say the time and weather based on the States of Weather Items

---

<div class="post-metadata">

**Author:** ![opus](https://community.openhab.org/user_avatar/community.openhab.org/opus/32/55801_2.png) [@opus](https://community.openhab.org/u/opus)\
**Post date:** [October 5, 2017, 7:27am UTC](https://community.openhab.org/t/announce-the-time-and-weather-via-tts/34813/3 "2017-10-05T07:27:01Z")

</div>

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 - #23 by opus](https://community.openhab.org/t/voicerss-customizing/34776/23)

---

<div class="post-metadata">

**Author:** ![Steven\_Ferguson](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/65b543/32.png) [@Steven\_Ferguson](https://community.openhab.org/u/Steven_Ferguson)\
**Post date:** [October 5, 2017, 11:00pm UTC](https://community.openhab.org/t/announce-the-time-and-weather-via-tts/34813/4 "2017-10-05T23:00:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [October 6, 2017, 12:49am UTC](https://community.openhab.org/t/announce-the-time-and-weather-via-tts/34813/5 "2017-10-06T00:49:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Steven\_Ferguson](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/65b543/32.png) [@Steven\_Ferguson](https://community.openhab.org/u/Steven_Ferguson)\
**Post date:** [October 9, 2017, 3:35pm UTC](https://community.openhab.org/t/announce-the-time-and-weather-via-tts/34813/6 "2017-10-09T15:35:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [October 9, 2017, 3:40pm UTC](https://community.openhab.org/t/announce-the-time-and-weather-via-tts/34813/7 "2017-10-09T15:40:59Z")

</div>

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

[This](http://docs.openhab.org/configuration/rules-dsl.html#conversions) section of the Rules docs probably provides the most in-depth discussion of how to access and manipulate an Item’s state.

---

<div class="post-metadata">

**Author:** ![opus](https://community.openhab.org/user_avatar/community.openhab.org/opus/32/55801_2.png) [@opus](https://community.openhab.org/u/opus)\
**Post date:** [October 9, 2017, 8:11pm UTC](https://community.openhab.org/t/announce-the-time-and-weather-via-tts/34813/8 "2017-10-09T20:11:12Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [October 9, 2017, 8:18pm UTC](https://community.openhab.org/t/announce-the-time-and-weather-via-tts/34813/9 "2017-10-09T20:18:41Z")

</div>

> [@opus](#):
>
> However, I won’t.

Been there, done that. I rarely will anymore.

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

---

<div class="post-metadata">

**Author:** ![Steven\_Ferguson](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/65b543/32.png) [@Steven\_Ferguson](https://community.openhab.org/u/Steven_Ferguson)\
**Post date:** [October 9, 2017, 9:31pm UTC](https://community.openhab.org/t/announce-the-time-and-weather-via-tts/34813/10 "2017-10-09T21:31:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [October 10, 2017, 1:48am UTC](https://community.openhab.org/t/announce-the-time-and-weather-via-tts/34813/11 "2017-10-10T01:48:04Z")

</div>

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)

```

---

<div class="post-metadata">

**Author:** ![Steven\_Ferguson](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/65b543/32.png) [@Steven\_Ferguson](https://community.openhab.org/u/Steven_Ferguson)\
**Post date:** [October 10, 2017, 2:33am UTC](https://community.openhab.org/t/announce-the-time-and-weather-via-tts/34813/12 "2017-10-10T02:33:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [October 10, 2017, 2:14pm UTC](https://community.openhab.org/t/announce-the-time-and-weather-via-tts/34813/13 "2017-10-10T14:14:57Z")

</div>

> [@Steven\_Ferguson](#):
>
> 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)

```

---

<div class="post-metadata">

**Author:** ![Steven\_Ferguson](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/65b543/32.png) [@Steven\_Ferguson](https://community.openhab.org/u/Steven_Ferguson)\
**Post date:** [October 10, 2017, 3:40pm UTC](https://community.openhab.org/t/announce-the-time-and-weather-via-tts/34813/14 "2017-10-10T15:40:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [October 10, 2017, 5:19pm UTC](https://community.openhab.org/t/announce-the-time-and-weather-via-tts/34813/15 "2017-10-10T17:19:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![opus](https://community.openhab.org/user_avatar/community.openhab.org/opus/32/55801_2.png) [@opus](https://community.openhab.org/u/opus)\
**Post date:** [October 10, 2017, 5:45pm UTC](https://community.openhab.org/t/announce-the-time-and-weather-via-tts/34813/16 "2017-10-10T17:45:05Z")

</div>

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](https://community.openhab.org/t/sonos-audio-sink-say/15576/70)  
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)

```

---

<div class="post-metadata">

**Author:** ![Steven\_Ferguson](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/65b543/32.png) [@Steven\_Ferguson](https://community.openhab.org/u/Steven_Ferguson)\
**Post date:** [October 10, 2017, 10:24pm UTC](https://community.openhab.org/t/announce-the-time-and-weather-via-tts/34813/17 "2017-10-10T22:24:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [October 10, 2017, 10:33pm UTC](https://community.openhab.org/t/announce-the-time-and-weather-via-tts/34813/18 "2017-10-10T22:33:58Z")

</div>

`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
```

````

---

<div class="post-metadata">

**Author:** ![Steven\_Ferguson](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/65b543/32.png) [@Steven\_Ferguson](https://community.openhab.org/u/Steven_Ferguson)\
**Post date:** [October 10, 2017, 11:05pm UTC](https://community.openhab.org/t/announce-the-time-and-weather-via-tts/34813/19 "2017-10-10T23:05:45Z")

</div>

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:

```auto
rule "Time and Temp"
when
    Item timeandtemp changed
then

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

```

---

<div class="post-metadata">

**Author:** ![Olymp](https://community.openhab.org/user_avatar/community.openhab.org/olymp/32/5553_2.png) [@Olymp](https://community.openhab.org/u/Olymp)\
**Post date:** [October 11, 2017, 1:58am UTC](https://community.openhab.org/t/announce-the-time-and-weather-via-tts/34813/20 "2017-10-11T01:58:21Z")

</div>

> [@Steven\_Ferguson](#):
>
> if ((timeandtemp.state == ON)) {
> 
> ```
> say ("The Time is "& currenttime.state.toString)
> 
> ```
> 
> }

try so, I did not check

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

```

[Next page](https://community.openhab.org/t/announce-the-time-and-weather-via-tts/34813.md?page=2)
