Hello,
I need help to extract some data and detect as state change.
This sensor code is use to check status in my onkyo avr:
- platform: command_line
scan_interval: 3
command_timeout: 2
name: onkyo_audiostatus
command: "/srv/homeassistant/bin/onkyo -q --host 192.168.11.70 IFAQSTN"
and status depend of what I play is
IFAHDMI 2,PCM,48 kHz,2.0 ch,Stereo,2.1 ch,
IFAHDMI 3,Multich PCM,48 kHz,5.1 ch,Multichannel,5.1 ch,
and I want make another sensor to detect data like “Multich PCM” “PCM” and set state with the same name or maybe I dont need another sensor but just custom code to read text I use this date do automation script.
Greetings and thank you!
petro
(Petro)
September 6, 2019, 11:55am
2
This should peel all the information out into 6 different sensors.
- platform: template
sensors:
onkyo_audiostatus_source:
friendly_name: 'Onkyo Source'
value_template: >
{{ states('sensor.onkyo_audiostatus').split(',')[0] }}
onkyo_audiostatus_info:
friendly_name: '????'
value_template: >
{{ states('sensor.onkyo_audiostatus').split(',')[1] }}
onkyo_audiostatus_frequency:
friendly_name: 'Onkyo Frequency'
value_template: >
{{ states('sensor.onkyo_audiostatus').split(',')[2] }}
onkyo_audiostatus_channel_1:
friendly_name: 'Onkyo Channel 1'
value_template: >
{{ states('sensor.onkyo_audiostatus').split(',')[3] }}
onkyo_audiostatus_audio_mode:
friendly_name: 'Onkyo Audio Mode'
value_template: >
{{ states('sensor.onkyo_audiostatus').split(',')[4] }}
onkyo_audiostatus_channel_2:
friendly_name: 'Onkyo Channel 2'
value_template: >
{{ states('sensor.onkyo_audiostatus').split(',')[5] }}
4 Likes
Omg thank you great code.
manjotsc
(Manjot Singh)
May 27, 2021, 2:50am
5
Hi,
I have similar situation, I need to extract data from this state
{'acc': '1', 'direction': '0', 'gpsSpeed': '0', 'gpsTime': '2021-05-26 15:41:30', 'latitude': 45.52569, 'longitude': -73.63071}
- platform: rest
name: Uplander LT
json_attributes:
- longitude
- latitude
- gpsSpeed
- acc
resource: https://example.com
value_template: "{{ value_json.data.gps }}"
scan_interval: 10
- platform: template
sensors:
uplander_lt_longitude:
friendly_name: "Uplander LT Longitude"
value_template: "{{ state_attr('sensor.uplander_lt', '.longitude') }}"
uplander_lt_latitude:
friendly_name: "Uplander LT Latitude"
value_template: "{{ state_attr('sensor.uplander_lt', '_latitude') }}"
uplander_lt_gpsspeed:
friendly_name: "Uplander LT Speed"
value_template: "{{ state_attr('sensor.uplander_lt', 'gpsSpeed') }}"
uplander_lt_acc:
friendly_name: "Uplander LT ACC"
value_template: "{{ state_attr('sensor.uplander_lt', 'acc') }}"
petro
(Petro)
May 27, 2021, 11:08am
6
remove the . and underscores on your tempalte sensors attributes inside the state_attr method. Also, you should try the new rest integration, you can do all of that in a single sensor.
manjotsc
(Manjot Singh)
May 27, 2021, 4:43pm
7
Thanks,
I used the rest integration. It all works. Can I make it device tracker by pulling longitude and latitude.
rest:
resource: https://example.com
scan_interval: 10
sensor:
- name: "Uplander LT GPS"
json_attributes_path: "data.gps"
value_template: "ok"
json_attributes:
- "longitude"
- "latitude"
- "gpsSpeed"
- "acc"