Open vashilov opened 1 year ago
7061.json
{
"manufacturer": "Samsung",
"supportedModels": [
"UA42J5200"
],
"supportedController": "ESPHome",
"commandsEncoding": "Hex",
"commands": {
"off": "0xE0E040BF",
"on": "0xE0E040BF",
"previousChannel": "0xE0E008F7",
"nextChannel": "0xE0E048B7",
"volumeDown": "E0E0D02F",
"volumeUp": "E0E0E01F",
"mute": "0xE0E0F00F",
"sources": {
"Channel 0": "0xE0E020DF",
"Channel 1": "0xE0E0A05F",
"Channel 2": "0xE0E0609F",
"Channel 3": "0xE0E010EF",
"Channel 4": "0xE0E0906F",
"Channel 5": "0xE0E050AF",
"Channel 6": "0xE0E0B04F",
"Channel 7": "0xE0E0708F",
"Channel 8": "0xE0E0807F",
"Channel 9": "0xE0E08877",
"Input": "0xE0E0807F"
}
}
}
HA
media_player:
- platform: smartir
name: Living room TV
unique_id: living_room_tv
device_code: 7061
delay: 1
controller_data: esp_03_send_samsung_command
EspHome
substitutions:
device_name: Esp_03
name: esp_03
esphome:
name: ${name}
platform: ESP8266
board: nodemcuv2
wifi:
ssid: !secret wifi_name_home
password: !secret wifi_password_home
ap:
ssid: "wifi_name Fallback Hotspot"
password: !secret esp_password_wifi
# Enable logging
logger:
# Enable Home Assistant API
api:
password: !secret esp_password
services:
- service: send_raw_command
variables:
command: int[]
then:
- remote_transmitter.transmit_raw:
code: !lambda 'return command;'
carrier_frequency: 37000
- service: send_samsung_command
variables:
command: string
then:
- remote_transmitter.transmit_samsung:
data: !lambda 'return strtoll(command.c_str(), NULL, 16);'
ota:
password: !secret esp_password
remote_transmitter:
pin:
number: D3
inverted: false
id: trs
carrier_duty_percent: 50%
controller.py
ESPHOME_COMMANDS_ENCODING = [ENC_RAW, ENC_HEX]
...
...
...
class ESPHomeController(AbstractController):
"""Controls a ESPHome device."""
def check_encoding(self, encoding):
"""Check if the encoding is supported by the controller."""
if encoding not in ESPHOME_COMMANDS_ENCODING:
raise Exception("The encoding is not supported "
"by the ESPHome controller.")
async def send(self, command):
"""Send a command."""
if self._encoding == ENC_RAW:
try:
service_data = {'command': json.loads(command)}
except:
raise Exception("Error while send raw")
if self._encoding == ENC_HEX:
try:
service_data = {'command': command}
except:
raise Exception("Error while send hex")
await self.hass.services.async_call(
'esphome', self._controller_data, service_data)
It work! for me))
Thank you very much! It helps to me too!
Sorry for my bad english.
I try add my stupid tv Samsung into smartir. I have only HEX codes for my TV.
Home Assistant version 2022.10.4
SmartIR version 1.17.6
1) create new service send_samsung_command in my esp_home SmartIR configuration
From HA this service work, and switсh on my TV. (code 0xE0E040BF)
2) in HA
3) cretae codes/media_player/7061.json (Raw, but need Hex)
Then I try push button on media_player I have error
Debug log
Please help me, i do not have raw codes from my TV. What i do wrong? I need example json file for Hex codes.