talormanda
(Talormanda)
November 9, 2022, 2:29am
1
{
"state": {
"litterrobot__status_code": {
"br": "Bonnet Removed",
"ccc": "Clean Cycle Complete",
"ccp": "Clean Cycle In Progress",
"cd": "Cat Detected",
"csf": "Cat Sensor Fault",
"csi": "Cat Sensor Interrupted",
"cst": "Cat Sensor Timing",
"df1": "Drawer Almost Full - 2 Cycles Left",
"df2": "Drawer Almost Full - 1 Cycle Left",
"dfs": "Drawer Full",
"dhf": "Dump + Home Position Fault",
"dpf": "Dump Position Fault",
"ec": "Empty Cycle",
"hpf": "Home Position Fault",
"off": "[%key:common::state::off%]",
"offline": "Offline",
"otf": "Over Torque Fault",
This file has been truncated. show original
alias: Test - Litter Robot
description: ""
trigger:
- platform: state
entity_id:
- sensor.litter_robot_status_code
condition: []
action:
- service: tts.google_translate_say
data:
entity_id: media_player.aaron_s_speakers
message: [litterrobot__status_code message here]
cache: true
mode: single
I wanted to create a TTS automation that would trigger every time the [sensor.litter_robot_status_code
] changes. The trigger works, however, I need to figure out how to do the TTS part. On the status codes linked above, there are 25 different status it can get. Instead of making 25 automations, I am seeking guidance if there is a way to grab the current status code message (for example: “Clean Cycle Complete”), and just use that.
pedolsky
(Pedolsky)
November 9, 2022, 3:49pm
2
As I can understand the documentation, the sensor already outputs a state as a human readable value.
Status Code - sensor
- Displays the status code (Clean Cycle in Progress, Ready, Drawer Full, etc).
If so, all you need is {{ trigger.to_state.state }}
in your message.
Additionally, I would use an automation condition to avoid unwanted messages:
condition:
- "{{ trigger.to_state.state != 'unavailable' and trigger.from_state.state != 'unavailable' }}"
(unless you want to be notified even if the sensor is not reachable)
talormanda
(Talormanda)
November 9, 2022, 4:07pm
3
So I tried this, and it worked, but it is saying the code and not the message itself.
I just had it come through and say “CCP” which is the code, but I want it to say the actual message in blue here. Is that possible?
service: tts.google_translate_say
data:
entity_id: media_player.aaron_s_room_speaker_1
message: "{{ trigger.to_state.state }}"
pedolsky
(Pedolsky)
November 9, 2022, 4:16pm
4
Can you please test it with
```
service: notify.persistent_notification
data:
message: “{{ trigger.entity_id }}: {{ trigger.to_state.state }}”
```
?
My post crossed with your editing.
pedolsky
(Pedolsky)
November 9, 2022, 4:28pm
5
Copy the following into Developer Tools ——> Template and tell me the result:
{% set status = states('sensor.litter_robot_status_code') %}
{% set code = {
"br": "Bonnet Removed",
"ccc": "Clean Cycle Complete",
"ccp": "Clean Cycle In Progress",
"cd": "Cat Detected",
"csf": "Cat Sensor Fault",
"csi": "Cat Sensor Interrupted",
"cst": "Cat Sensor Timing",
"df1": "Drawer Almost Full - 2 Cycles Left",
"df2": "Drawer Almost Full - 1 Cycle Left",
"dfs": "Drawer Full",
"dhf": "Dump + Home Position Fault",
"dpf": "Dump Position Fault",
"ec": "Empty Cycle",
"hpf": "Home Position Fault",
"off": "[%key:common::state::off%]",
"offline": "Offline",
"otf": "Over Torque Fault",
"p": "[%key:common::state::paused%]",
"pd": "Pinch Detect",
"pwrd": "Powering Down",
"pwru": "Powering Up",
"rdy": "Ready",
"scf": "Cat Sensor Fault At Startup",
"sdf": "Drawer Full At Startup",
"spf": "Pinch Detect At Startup"
} %}
{{ code[status] if status in code.keys() else 'no status' }}
talormanda
(Talormanda)
November 9, 2022, 4:31pm
6
pedolsky:
{% set status = states('sensor.litter_robot_status_code') %}
{% set code = {
"br": "Bonnet Removed",
"ccc": "Clean Cycle Complete",
"ccp": "Clean Cycle In Progress",
"cd": "Cat Detected",
"csf": "Cat Sensor Fault",
"csi": "Cat Sensor Interrupted",
"cst": "Cat Sensor Timing",
"df1": "Drawer Almost Full - 2 Cycles Left",
"df2": "Drawer Almost Full - 1 Cycle Left",
"dfs": "Drawer Full",
"dhf": "Dump + Home Position Fault",
"dpf": "Dump Position Fault",
"ec": "Empty Cycle",
"hpf": "Home Position Fault",
"off": "[%key:common::state::off%]",
"offline": "Offline",
"otf": "Over Torque Fault",
"p": "[%key:common::state::paused%]",
"pd": "Pinch Detect",
"pwrd": "Powering Down",
"pwru": "Powering Up",
"rdy": "Ready",
"scf": "Cat Sensor Fault At Startup",
"sdf": "Drawer Full At Startup",
"spf": "Pinch Detect At Startup"
} %}
{{ code[status] if status in code.keys() else 'no status' }}
this is interesting. can you explain what this is that you had me put in? its a bit foreign to me but i would like to learn it.
pedolsky
(Pedolsky)
November 9, 2022, 5:27pm
7
The code
variable represents a dictionary, in it there are key-value-pairs (e.g. “cst” stands for “Cat Sensor Timing”). B we need to identify the right pair (and so the wanted output). This we do by comparing the state of your sensor with existing items in the dictionary using {{ code[status] }}
To avoid a bad result, we combine it with a condition: If there is no existing key in the dictionary that matches the state of your sensor = if status in code.keys()
then return 'no status'
.
My English is miserable, I hope you can follow.
P.S.: Maybe it is getting clearer by copying these code snippets additionally into Developer Tools:
{{ code[status] }}
{{ code.keys() }}
{{ code.values() }}
talormanda
(Talormanda)
November 9, 2022, 6:37pm
8
Do I need to copy that code dictionary into my automation now to get it to work?
pedolsky
(Pedolsky)
November 9, 2022, 7:11pm
9
You can put it in your message field:
alias: Test - Litter Robot
description: ""
trigger:
- platform: state
entity_id:
- sensor.litter_robot_status_code
condition: []
action:
- service: tts.google_translate_say
data:
entity_id: media_player.aaron_s_speakers
message: |-
{% set status = trigger.to_state.state %}
{% set code = … %}
{{ code[status]|replace("[%key:common::state::paused%]", "paused") |replace("[%key:common::state::off%]", "off") if status in code.keys() else 'no status' }}
cache: true
mode: single
I’ve added to replace rules.
talormanda
(Talormanda)
November 9, 2022, 7:47pm
10
Sorry. Do not understand. What does “I’ve added to replace rules.” mean?
pedolsky
(Pedolsky)
November 9, 2022, 8:21pm
11
I don’t know how is this processed by tts:
"off": "[%key:common::state::off%]"
"p": "[%key:common::state::paused%]"
So I’ve added readable labels (off and paused):
{{ code[status]|replace("[%key:common::state::paused%]", "paused") |replace("[%key:common::state::off%]", "off")
Otherwise, it may be that your speaker says “[%key:common::state::off%]”
talormanda
(Talormanda)
November 9, 2022, 8:23pm
12
Gotcha, where do I put the dictionary from earlier in there? At which spot?
pedolsky
(Pedolsky)
November 9, 2022, 8:27pm
13
In the ‘code’ line
message: |-
{% set status = trigger.to_state.state %}
{% set code = … %}
talormanda
(Talormanda)
November 9, 2022, 8:34pm
14
Okay, here is what I pasted in, and the error I get:
alias: Test - Litter Robot
description: ""
trigger:
- platform: state
entity_id:
- sensor.litter_robot_status_code
condition: []
action:
- service: tts.google_translate_say
data:
entity_id: media_player.aaron_s_speakers
message: |-
{% set status = trigger.to_state.state %}
{% set code =
"br": "Bonnet Removed",
"ccc": "Clean Cycle Complete",
"ccp": "Clean Cycle In Progress",
"cd": "Cat Detected",
"csf": "Cat Sensor Fault",
"csi": "Cat Sensor Interrupted",
"cst": "Cat Sensor Timing",
"df1": "Drawer Almost Full - 2 Cycles Left",
"df2": "Drawer Almost Full - 1 Cycle Left",
"dfs": "Drawer Full",
"dhf": "Dump + Home Position Fault",
"dpf": "Dump Position Fault",
"ec": "Empty Cycle",
"hpf": "Home Position Fault",
"off": "[%key:common::state::off%]",
"offline": "Offline",
"otf": "Over Torque Fault",
"p": "[%key:common::state::paused%]",
"pd": "Pinch Detect",
"pwrd": "Powering Down",
"pwru": "Powering Up",
"rdy": "Ready",
"scf": "Cat Sensor Fault At Startup",
"sdf": "Drawer Full At Startup",
"spf": "Pinch Detect At Startup"
%}
{{ code[status]|replace("[%key:common::state::paused%]", "paused") |replace("[%key:common::state::off%]", "off") if status in code.keys() else 'no status' }}
cache: true
mode: single
pedolsky
(Pedolsky)
November 9, 2022, 8:47pm
15
It has to be the code you copied into Developer Tools.
message: |-
{% set status = trigger.to_state.state %}
{% set code = {
"br": "Bonnet Removed",
"ccc": "Clean Cycle Complete",
… and so on…
} %}
talormanda
(Talormanda)
November 9, 2022, 8:48pm
16
oh. do i need to remove that out of there? i fixed the code and removed the developer template but still get that error
pedolsky
(Pedolsky)
November 9, 2022, 10:02pm
17
Looks your automation like that?
alias: Test - Litter Robot
description: ""
mode: single
trigger:
- platform: state
entity_id:
- sensor.litter_robot_status_code
condition: []
action:
- service: tts.google_translate_say
data:
entity_id: media_player.aaron_s_speakers
message: |-
{% set status = trigger.to_state.state %}
{% set code = {
"br": "Bonnet Removed",
"ccc": "Clean Cycle Complete",
"ccp": "Clean Cycle In Progress",
"cd": "Cat Detected",
"csf": "Cat Sensor Fault",
"csi": "Cat Sensor Interrupted",
"cst": "Cat Sensor Timing",
"df1": "Drawer Almost Full - 2 Cycles Left",
"df2": "Drawer Almost Full - 1 Cycle Left",
"dfs": "Drawer Full",
"dhf": "Dump + Home Position Fault",
"dpf": "Dump Position Fault",
"ec": "Empty Cycle",
"hpf": "Home Position Fault",
"off": "[%key:common::state::off%]",
"offline": "Offline",
"otf": "Over Torque Fault",
"p": "[%key:common::state::paused%]",
"pd": "Pinch Detect",
"pwrd": "Powering Down",
"pwru": "Powering Up",
"rdy": "Ready",
"scf": "Cat Sensor Fault At Startup",
"sdf": "Drawer Full At Startup",
"spf": "Pinch Detect At Startup"
} %}
{{ code[status]|replace("[%key:common::state::paused%]", "paused") |replace("[%key:common::state::off%]", "off") if status in code.keys() else 'no status' }}
cache: true
talormanda
(Talormanda)
November 9, 2022, 10:13pm
18
Sorry, I don’t understand now. Because it’s literally the same as what you put, but now it saves? Really odd…
pedolsky
(Pedolsky)
November 9, 2022, 10:17pm
19
Your code
{% set code =
"br": "Bonnet Removed",
My code
{% set code = {
"br": "Bonnet Removed",
} %}
The dictionary has to be within { }
talormanda
(Talormanda)
November 9, 2022, 10:18pm
20
gotcha. that did it, and it looks like its working too.