Last active
June 11, 2022 15:21
-
-
Save malinovsku/3a684784f50324e7954dbe8b5b849628 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################# | |
Создать службу для записи в файл | |
notify: | |
- name: rk_automatic_temperature_l6 | |
platform: file | |
filename: /config/txt/rk_automatic_temperature_l6.csv | |
################################################################################# | |
Создать файл /config/txt/rk_automatic_temperature_l6_bk.csv | |
В шапку файла прописать TIME,VALUE | |
################################################################################# | |
Установить инетеграцию https://github.com/AlexxIT/PythonScriptsPro для сенсора | |
################################################################################# | |
Создать файл скрипта для сенсора по расположению и имени: /config/python_scripts/csv_file.py | |
import csv | |
file_parse = self.config['file_parse'] | |
results = [] | |
with open(file_parse, 'rU') as infile: | |
reader = csv.DictReader(infile) | |
for row in reader: | |
results.append(row) | |
self.state = file_parse.split(".")[0] | |
self.attributes={} | |
self.attributes['friendly_name'] = self.config['name'] | |
self.attributes['icon'] = 'mdi:file-eye-outline' | |
self.attributes['file'] = results | |
################################################################################# | |
добавитить сенсор | |
sensor: | |
- platform: python_script | |
name: rk_automatic_temperature_l6 | |
scan_interval: '00:01:00' | |
file_parse: '/config/txt/rk_automatic_temperature_l6.csv' | |
file: /config/python_scripts/csv_file.py | |
################################################################################# | |
Cлужба для затирки файла, записи по новой | |
shell_command: | |
rk_automatic_temperature_l6_reload_file: cp /config/txt/rk_automatic_temperature_l6_bk.csv /config/txt/rk_automatic_temperature_l6.csv | |
################################################################################# | |
Карточка для ловеласа | |
type: markdown | |
content: |- | |
## Показания СЕНСОРА | |
|TIME|VALUE| | |
|:----|--------:| | |
{%- set rr = (state_attr("sensor.rk_automatic_temperature_l6","file"))-%} | |
{%-for ee in rr%} | |
|__{{ee.TIME}}__|__<font color = orange>{{ee.VALUE|float(default="not")}}__| | |
{%-endfor-%} | |
################################################################################# | |
Переключатель вкл выкл запись в файл каждые 10 мин (0\10\20\30...) | |
input_boolean: | |
rk_automatic_temperature_l6_save_file: | |
name: rk_automatic_temperature_l6_save_file | |
################################################################################# | |
Автоматизация для обновления файла при включении записи | |
alias: обновление файла rk_automatic_temperature_l6 при включении записи | |
description: '' | |
mode: single | |
trigger: | |
- platform: state | |
entity_id: | |
- input_boolean.rk_automatic_temperature_l6_save_file | |
to: 'on' | |
not_from: | |
- unavailable | |
- unknown | |
condition: [] | |
action: | |
- service: shell_command.rk_automatic_temperature_l6_reload_file | |
data: {} | |
################################################################################# | |
Автоматизация для записи инфы в файл каждые 10 минут (0\10\20\30...) | |
alias: запись инфы в файл rk_automatic_temperature_l6 | |
description: '' | |
mode: single | |
trigger: | |
- platform: time_pattern | |
minutes: /10 | |
condition: | |
- condition: state | |
entity_id: input_boolean.rk_automatic_temperature_l6_save_file | |
state: 'on' | |
action: | |
- service: notify.rk_automatic_temperature_l6 | |
data: | |
message: "{{now().strftime('%H:%M:%S')}}, {{states('sensor.rk_automatic_temperature_l6')}}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment